该代码仅供商店参考。他们从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,它就会停滞不前,因为循环条件永远不会改变。 –