-1

I have my program ask what attack you want and it supposed to get the spells from a list who gets the attacks from def's and I'm getting this error

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

And my code: (Sorry it is so long but i tried to cut it down to the relevant loop and this is as small as i could cut it 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 you sure you want to be a %s' % (school_name))
input_str = input()
if input_str.lower().startswith("N"):
    choose_school()
Innlion
  • 11
  • 7

2 Answers2

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

player_spells is a set not a list and somewhere inside one of the elements you are trying to store is also a set which is causing your error.

If you want a list, you create it with [] not {}:

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

I think tutorials on lists and if/elif/else won't hurt.

Use elifs instead of all 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 are True you need to set a value for school_name
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
  • `print('are you sure you want to be a %s' % (school_name)) NameError: name 'school_name' is not defined` – Innlion Oct 05 '14 at 17:46
  • That means none of your of statements evaluate to True, add `else:school_name = "foo"` and run it again – Padraic Cunningham Oct 05 '14 at 17:48
  • also use `if/elif's` not all ifs – Padraic Cunningham Oct 05 '14 at 17:48
  • now there is no errors but it keeps on asking for input over and over – Innlion Oct 05 '14 at 17:55
  • you should try debugging, I have answered two questions already, if you have more questions I suggest you ask a different question after you have tried to figure out what is wrong yourself first. One big clue is a loop has to break somehow when a certain condition is met or else it will loop forever. You seem to have a poor understanding of the basics, you would be better off learning the basics well before trying to write code. – Padraic Cunningham Oct 05 '14 at 17:58
  • You're welcome, I strongly suggest you look at those links I posted, there are tutorials on all the basics on that site – Padraic Cunningham Oct 05 '14 at 18:02
0

sets allows you to do operations such as intersection, union, difference, and symmetric difference, i.e operations of math's set theory. Sets doesn't allow indexes are are implemented on hash tables.

lists are are really variable-length arrays, not Lisp-style linked lists. In lists the elements are accessed by indexes. Addition to this padraic also suggested that you are using set not list. So you are getting an error

For more refer the difference between set and list

Community
  • 1
  • 1
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56