我有一个简单的Python程序,询问是或否的问题,并验证输入。 如果我运行这个Python shell,它运行良好。如果我输入无效字符,它会循环回到最上面。python程序在python shell与终端中表现不同
但是,如果我在终端窗口中运行此操作,并尝试输入无效字符,则会出现如下所示的错误。
endProgram = 0
while endProgram != 1:
userInput = input("Yes or No? ");
userInput = userInput.lower();
while userInput not in ['yes', 'no']:
print("Try again.")
break
endProgram = userInput == 'no'
您是否在两者上使用相同的Python版本? 'input'在2和3之间改变行为。 – tzaman