您正在测试用户输入 是否为
yes或
no。添加一个
not:
while userInput not in ['yes', 'no']:
如此快一点,更接近您的意图,请使用一组:
while userInput not in {'yes', 'no'}:你用什么的
userInput in ['yes', 'no'],这是
True如果
userInput是要么等于
'yes'或
'no'。
接下来,使用布尔值设置
endProgram:
endProgram = userInput == 'no'
因为你已经验证了
userInput或者是
yes或
no,没有必要测试
yes或
no重新设置你的标志变量。



