該代碼僅供商店參考。他們從400金開始,如果他們挑選的產品太貴,會詢問他們是否願意選擇另一個。我的問題是,如果他們選擇一個他們可以承受的無限循環while循環,我不知道爲什麼。while循環無限循環,如果它達到elif語句
shopitemsF = ["Ghostblade: 150 Damage, Cost: 700", "Thunderblade: 120 Damage, Cost: 300", "Bloodcursed Sword: 160 Damage, Cost 800"]
shopitemsM = ["Fire Throw: 150 Damage, Cost: 700", "Ice Wind: 120 Damage, Cost: 300", "Electric shock: 160 Damage, Cost 800"]
print("Welcome to the shop.")
print('')
if character == "Fighter":
g = ', '
print(g.join(shopitemsF))
time.sleep(1)
elif character == "Mage":
g = ', '
print(g.join(shopitemsM))
time.sleep(1)
shopchoice = input("Please pick another item? ")
print('')
while True:
for text2 in shopitemsF:
if shopchoice in text2:
print(text2)
if int(text2[-3:]) >= gold:
print("You need another", int(text2[-3:]) - gold, "gold.")
shopchoice = input("Please pick another item? ")
break
elif int(text2[-3:]) <= gold:
print("You have purchased,", text2[:-11]+".")
x = (int(text2[-21:-18]))
for text2 in shopitemsM:
if shopchoice in text2:
print(text2)
if int(text2[-3:]) >= gold:
print("You need another", int(text2[-3:]) - gold, "gold.")
shopchoice = input("Please pick another item? ")
break
elif int(text2[-3:]) <= gold:
print("You have purchased,", text2[:-11]+".")
x = (int(text2[-21:-18]))
哪個elif語句?這聽起來像有一些外部循環條件,它在'if'中更改,但不在'elif'中。因此,只要它碰到elif,它就會停滯不前,因爲循環條件永遠不會改變。 –