Python 我的while循环不是';t为输入验证工作
试试这个:Python 我的while循环不是';t为输入验证工作,python,validation,if-statement,while-loop,Python,Validation,If Statement,While Loop,试试这个: end_program = False while end_program == False: user_choice = input('\nWould you like to play a game?\n Please pick yes or no\n').lower() if user_choice != 'yes' or 'no': print('You didn\'t pick yes or no...try again please\n')
end_program = False
while end_program == False:
user_choice = input('\nWould you like to play a game?\n Please pick yes or no\n').lower()
if user_choice != 'yes' or 'no':
print('You didn\'t pick yes or no...try again please\n')
end_program = False
else:
end_program = True
在检查多个条件时,您需要明确:
你不能说:
如果用户选择!='“是”或“否”
此处的“否”是导致错误的原因。您需要单独检查以下情况:
end_program = False
while end_program == False:
user_choice = input('\nWould you like to play a game?\n Please pick yes or
no\n').lower()
if user_choice != 'yes' or user_choice !='no':
print('You didn\'t pick yes or no...try again please\n')
end_program = False
else:
end_program = True
if user_choice != 'yes' or user_choice != 'no':