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 に答える