程序在while循环中卡住,尽管它看起来是正确的



由于某种原因,它在while循环中第一次请求输入";userChoice";,有人有解决方案吗?

userStart = input("n Enter UBM? n (Yes) n (No)")
while userStart == "Yes":
p1 = bank(1234, "Bank Bill", "dragon123", 300)
p2 = bank(1235, "Billy Jones", "cookies1231", 300)
p3 = bank(1236, "Johnny Test", "beans100", 300)
userChoice = input("n You arrive at UBM; The United Bank of MONEY. What account would you like to access? n (Bank Bill) n (Billy Jones) n (Johnny Test) n ")
if userChoice == "Bank Bill":
p1.passCheck()
userStart = input("n Stay in UBM? n (Yes) n (No)")
elif userChoice == "Billy Jones":
p2.passCheck()
userStart = input("n Stay in UBM? n (Yes) n (No)")
elif userChoice == "Johnny Test":
p3.passCheck()
userStart = input("n Stay in UBM? n (Yes) n (No)")
if userStart == "No":
print("You left UBM.")

您可能想要规范化输出并比较规范化的结果。您的结果可能包含空格。

normalized_yes_response = "yes"
while userStart == normalized_yes_response:
...
userStart = input("n Stay in UBM? n (Yes) n (No)").lower().strip()

相关内容

最新更新