Saturday 15 August 2015

python - why is my list getting an error? -



python - why is my list getting an error? -

i have programme inquire attack want , supposed spells list gets attacks def's , i'm getting error

player_spells = {fire_spells, ice_spells, water_spells, chaos_spells, nature_spells, spirit_spells, equilibrium_spells, intellectual_spells} typeerror: unhashable type: 'set'

and code: (sorry long tried cutting downwards relevant loop , little cutting down)

toutorial_dialoug() enemy_health = 0 player_health = 0 player_max_health = 0 def ember(): ember = enemy_health - random.randint(95, 125) def flame(): flame = enemy_health - random.randint(155, 185) def inferno(): inferno = enemy_health - random.randint(250, 285) def lava_river(): lava_river = enemy_health - random.randint(300, 400) def snowflake(): snowflake = enemy_health - random.randint(75, 100) def blizard(): blizard = enemy_health - random.randint(135, 200) def frostbite(): frostbite = enemy_health - random.randint(225, 265) def frozen_lake(): frozen_lake = enemy_health - random.randint(300, 345) def tropical_storm(): tropical_storm = enemy_health - random.randint(125, 145) def hurricane(): hurricane = enemy_health - random.randint(200, 255) def tornado(): tornado = enemy_health - random.randint(300, 350) def bubble(): bubble = enemy_health - random.randint(425, 500) def raining_cats_and_dogs(): raining_cats_and_dogs = enemy_health - random.randint(95, 125) def summon_hades(): summon_hades = enemy_health - random.randint(155, 185) def burning_sky(): burning_sky = enemy_health - random.randint(250, 285) def swap_pips(): swap_pips = enemy_health - random.randint(300, 345) def pans_wraith(): pans_wraith = enemy_health - random.randint(90, 110) def bees_knees(): bees_knees = player_health + 400 def deforestation(): deforestation = enemy_health - random.randint(200, 255) def earth_shaker(): earth_shaker = enemy_health - random.randint(285, 330) def ghost_touch(): ghost_touch = enemy_health - 100, player_health + 50 def lost_soul(): lost_soul = enemy_health - 200, player_health + 100 def death_pixie(): death_pixie = enemy_health - 300, player_health + 150 def pathogen(): pathogen = enemy_health - random.randint(412, 445) def pulse(): pulse = enemy_health - random.randint(85, 112) def blind(): blind = enemy_health - random.randint(185, 215) def overload(): overload = enemy_health - random.randint(245, 315) def equalizer(): equalizer = enemy_health - random.randint(300, 400) def acid(): acid = enemy_health - random.randint(70, 90) def light_overload(): light_overload = enemy_health - random.randint(100, 120) def sound_overload(): sound_overload = enemy_health - random.randint(200, 220) def time(): time = enemy_health - random.randint(300, 330) fire_spells = {ember(), flame(), inferno(), lava_river()} ice_spells = {snowflake(), blizard(), frostbite(), frozen_lake()} water_spells = {tropical_storm(), hurricane(), tornado(), bubble()} chaos_spells = {raining_cats_and_dogs(), summon_hades(), burning_sky(), swap_pips()} nature_spells = {pans_wraith(), bees_knees(), deforestation(), earth_shaker()} spirit_spells = {ghost_touch(), lost_soul(), death_pixie(), pathogen()} equilibrium_spells = {pulse(), blind(), overload(), equalizer()} intellectual_spells = {acid(), light_overload(), sound_overload(), time()} player_spells = {fire_spells, ice_spells, water_spells, chaos_spells, nature_spells, spirit_spells, equilibrium_spells, intellectual_spells} def choose_school(): have_school = false while false: input_str = input() if input_str.lower().startswith("i"): player_spells = player_spells[2] player_max_health = 525 player_health = 525 player_level = 1 have_school = true elif input_str.lower().startswith("f"): player_spells = player_spells[1] player_max_health = 425 player_health = 425 player_level = 1 have_school = true elif input_str.lower().startswith("w"): player_spells = player_spells[3] player_max_health = 400 player_health = 400 player_level = 1 have_school = true elif input_str.lower().startswith("c"): player_spells = player_spells[4] player_max_health = 425 player_health = 425 player_level = 1 have_school = true elif input_str.lower().startswith("n"): player_spells = player_spells[5] player_max_health = 465 player_health = 465 player_level = 1 have_school = true elif input_str.lower().startswith("s"): player_spells = player_spells[6] player_max_health = 450 player_health = 450 player_level = 1 have_school = true elif input_str.lower().startswith("e"): player_spells = player_spells[7] player_max_health = 480 player_health = 480 player_level = 1 have_school = true elif input_str.lower().startswith("t"): player_spells = player_spells[8] player_max_health = 500 player_health = 500 player_level = 1 have_school = true choose_school() if player_health > player_max_health: while true: player_health - 1 if player_spells == ice_spells: school_name = 'ice wizard' if player_spells == fire_spells: school_name = 'fire wizard' if player_spells == water_spells: school_name = 'water wizard' if player_spells == chaos_spells: school_name = 'chaos wizard' if player_spells == nature_spells: school_name = 'nature wizard' if player_spells == spirit_spells: school_name = 'spirit wizard' if player_spells == equilibrium_spells: school_name = 'equilibrium wizard' if player_spells == intellectual_spells: school_name = 'ice wizard' print('are sure want %s' % (school_name)) input_str = input() if input_str.lower().startswith("n"): choose_school()

player_spells = {fire_spells, ice_spells, water_spells, chaos_spells, nature_spells, spirit_spells, equilibrium_spells, intellectual_spells}

player_spells set not list , somewhere within 1 of elements trying store set causing error.

if want list, create [] not {}:

player_spells = [fire_spells, ice_spells, water_spells, chaos_spells, nature_spells, spirit_spells, equilibrium_spells, intellectual_spells]

i think tutorials on lists , if/elif/else won't hurt.

use elifs instead of if's:

if player_spells == ice_spells: school_name = 'ice wizard' elif player_spells == fire_spells: school_name = 'fire wizard' elif player_spells == water_spells: school_name = 'water wizard' elif player_spells == chaos_spells: school_name = 'chaos wizard' elif player_spells == nature_spells: school_name = 'nature wizard' elif player_spells == spirit_spells: school_name = 'spirit wizard' elif player_spells == equilibrium_spells: school_name = 'equilibrium wizard' elif player_spells == intellectual_spells: school_name = 'ice wizard' else: school_name = "whatever" # in case none true need set value school_name

python python-3.x text-based

No comments:

Post a Comment