-1

私は自分のプログラムにあなたが望む攻撃を尋ねさせ、それは から攻撃を受けるリストから呪文を取得することになっていて、defこのエラーが発生しています

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

そして私のコード:(申し訳ありませんが、非常に長いですが、関連するループに切り詰めようとしましたが、これは切り詰めることができるほど小さいです)

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()
4

2 に答える 2

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

player_spellsはリストではなくセットであり、保存しようとしている要素の 1 つの内部のどこかにset、エラーの原因となっているものもあります。

リストが必要な場合は、[]notを使用して作成し{}ます。

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

リストif/elif/elseのチュートリアルは問題ないと思います。

elifsすべての if の代わりに使用:

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
于 2014-10-05T17:43:14.773 に答える
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

于 2014-10-05T17:49:51.183 に答える