assassin_weapons = {'dagger':6,'blade':10,'hidden_blade':7,'sai':7,'tomahawk':11,'spear':9}
assassin_armour = {'chest_guard':21,'gauntlets':6,'boots':9,'hood':12,'cape':16}
def store():
if char_class == 'Assassin':
time.sleep(0.6)
print(assassin_weapons)
time.sleep(0.6)
purchase = input("Which item(s) do you want to purchase?: ")
for key in assassin_weapons:
if key == purchase:
Assassin.unequipped.update(**assassin_weapons[key])
print(Assassin.unequipped)
答案 0 :(得分:0)
此循环是不必要的,因为您只有一个键,而不必通过字典来循环获得它。
for key in assassin_weapons:
if key == purchase:
Assassin.unequipped.update(**assassin_weapons[key])
print(Assassin.unequipped)
我认为您想要做的是,获取他购买的物品并将其带到Assassin.unequipped
词典中?
如果是,则获取该键和值并将其添加到新字典中。
if purchase in assassin_weapons:
if purchase in Assassin.unequipped:
Assassin.unequipped[purchase]+=assassin_weapons[purchase]
else:
Assassin.unequipped[purchase]=assassin_weapons[purchase]
# type 1 instead of assassin_weapons[purchase] if you want only one item to purchase