0

基本上,用户更早地选择了一个类。在这个菜单中,它会检查,如果用户选择了巫师,那么他们可以选择最多花费 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

我的问题是循环永远不会结束。当没有更多的法术点时应该是这样,但它并没有结束。提前谢谢了。

4

1 回答 1

4

尝试这个:

Spellpoints -= 1

对于其他变量也是如此。

Spellpoints - 1什么都不做;它只是返回返回结果而不修改变量。为了更改变量,您必须将结果分配回它。x -= 1是 的简写x = x - 1,其中-=减法赋值运算符。其他算术运算也存在类似的运算符。

于 2013-02-01T08:50:48.217 回答