允许大写 "Yes" 输入和非大写 "yes" 输入或 Python 中的值的正确方法是什么?
What is the proper way to allow a capitalized "Yes" input and a non-capitalized "yes" input or value in Python?
'''
我试图让用户键入大写 "Yes" 作为输入或非大写 "yes" 作为输入,并且仍然获得变量的 'True' 值,与 'phone' 或 'Phone' 变量,援助。
print ('Do you want to take the Carona Test in North Carolina: Type in
"Yes or No"')
good='Yes'
aid='phone'
good = input()
if good == 'Yes':
print ('The address is 1801 Glendale Dr SW, Wilson, NC 27893. ' +
'If you need the Helpline, type "phone" and if not type in "No".')
aid = input()
if aid=='phone':
print("NC CDC Help Line 1-866-462-3821. Don't forget to wash
your hands.")
else:
print('You have elected to do nothing silly human scum, good luck.')
'''
尝试这样的事情:
x = input('...')
if(x == 'Yes' or x == 'yes'):
print('True')
else:
print('False')
对于完全不区分大小写的解决方案,将用户输入转换为小写或大写。
if input('Do you want the Coronavirus test in NC?').lower() == 'yes':
print('Instructions here')
else:
print('Okay')
''' 我试图让用户键入大写 "Yes" 作为输入或非大写 "yes" 作为输入,并且仍然获得变量的 'True' 值,与 'phone' 或 'Phone' 变量,援助。
print ('Do you want to take the Carona Test in North Carolina: Type in
"Yes or No"')
good='Yes'
aid='phone'
good = input()
if good == 'Yes':
print ('The address is 1801 Glendale Dr SW, Wilson, NC 27893. ' +
'If you need the Helpline, type "phone" and if not type in "No".')
aid = input()
if aid=='phone':
print("NC CDC Help Line 1-866-462-3821. Don't forget to wash
your hands.")
else:
print('You have elected to do nothing silly human scum, good luck.')
'''
尝试这样的事情:
x = input('...')
if(x == 'Yes' or x == 'yes'):
print('True')
else:
print('False')
对于完全不区分大小写的解决方案,将用户输入转换为小写或大写。
if input('Do you want the Coronavirus test in NC?').lower() == 'yes':
print('Instructions here')
else:
print('Okay')