基本上,用户之前选择了一个班级。在此菜单中,它会检查,如果用户选择了向导,那么他们可以选择最多花费4个技能点。
if Class == ("wizard") or Class == ("Wizard"):
print("You have four spell points. You can learn up to four level- one spells, or one level-four spell, or any combination thereof.")
Spellpoints = 4
FireballLvl = 0
IceBlastLvl = 0
TelekeniticSheildLvl = 0
ElectricShockLvl = 0
WindLvl = 0
while True:
Spellmenu = input("Press 1 to spend a point on Fireball. Press 2 to spend a point on Ice Blast. Press 3 to spend a point on Telekenitic Sheild. Press 4 to spend a point on Electric Shock. Press 5 to spend a point on Wind.")
if Spellpoints == 0:
print ("You have no more spell points")
break
if Spellmenu == ("1"):
Spellpoints - 1
FireballLvl + 1
elif Spellmenu == ("2"):
Spellpoints - 1
IceBlastLvl + 1
elif Spellmenu ==("3"):
Spellpoints - 1
TelekeniticSheildLvl + 1
elif Spellmenu ==("4"):
Spellpoints - 1
ElectricShockLvl + 1
elif Spellmenu ==("5"):
Spellpoints - 1
WindLvl + 1
我的问题是循环永远不会结束。它应该在没有更多的法术点时,但它不会结束。提前谢谢了。
答案 0 :(得分:4)
试试这个:
Spellpoints -= 1
同样适用于其他变量。
Spellpoints - 1
没有做任何事情;它只返回返回结果而不修改变量。要更改变量,必须将结果返回给它。 x -= 1
是x = x - 1
的简写,其中-=
是减法赋值运算符。其他算术运算也存在类似的运算符。