Python 3.x 什么是允许“大写”的正确方式;是”;输入和非大写的“输入”;是”;Python中的输入还是值?
''' 我试图允许用户键入大写的“是”作为输入,或键入不大写的“是”作为输入,但仍然可以获得变量的“真”值,很好,与变量的“phone”或“phone”相同,aidPython 3.x 什么是允许“大写”的正确方式;是”;输入和非大写的“输入”;是”;Python中的输入还是值?,python-3.x,input,case,case-insensitive,Python 3.x,Input,Case,Case Insensitive,''' 我试图允许用户键入大写的“是”作为输入,或键入不大写的“是”作为输入,但仍然可以获得变量的“真”值,很好,与变量的“phone”或“phone”相同,aid 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': pr
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,并让它作为“Yes”或“不区分大小写”来使用打印功能。我的打印内容保持原样,不需要修改。答案是:如果(good=='Yes'或good=='Yes'):谢谢你,康纳,干得好!我感谢康纳的回答——他答对了。但是我现在很好奇是否会提出同样的请求——但是为了解决用户不区分大小写的问题,是的,是的,是的。。。