我对Python和stackoverflow社区相对较新,并希望在编写我的第一个“helloworld文件”时找到一些特定问题的帮助。
问题在于我找不到从两个不同的输入字符串结果中打印一个答案的方法......
if information == ("Yes" or "yes") : #still trying to figure out how to make the program respond with "Ok" with both the inputs, "Yes" and "yes"
print('Ok')
print('Ok')
任何帮助/答案都会有很大帮助。
答案 0 :(得分:0)
您可以查看是否包含:
if information in ("Yes", "yes"):
print('Ok')
或:
if information.lower() == "yes":
print('Ok')
答案 1 :(得分:0)
if information == "Yes" or information == "yes":
print('Ok')
print('Ok')
或
if information in ('yes', 'Yes', 'YES'):
print('Ok')
print('Ok')
另一种方式是:
if information.lower() == "yes":
print('Ok')
print('Ok')
或懒惰的方式:
if information.lower().startwith("y"):
print('Ok')
print('Ok')
希望它按预期工作
答案 2 :(得分:-1)
试试这个
if information == "Yes" or information == 'yes':
希望这有帮助