[英]Program stuck in while loop even though it seems correct
For some reason this gets stuck in a while loop at where it first asks for an input in "userChoice", anyone have a solution?由于某种原因,这在它首先要求输入“userChoice”的地方陷入了一个while循环,有人有解决方案吗?
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.")
You probably want to normalize the output and compare the normalized result.您可能想要标准化 output 并比较标准化结果。 Your result probably contains the linefeed.您的结果可能包含换行符。
normalized_yes_response = "yes"
while userStart == normalized_yes_response:
...
userStart = input("\n Stay in UBM? \n (Yes) \n (No)").lower().strip()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.