【发布时间】:2019-07-04 23:03:01
【问题描述】:
我的代码:
answer = str(raw_input("Is the information correct? Enter Y for yes or N for no"))
if answer == "y" or answer == "Y":
print("this will do the calculation")
else:
exit()
这种方式与OR运算符一起使用是否正确?
【问题讨论】:
-
你可以使用
if answer.lower() == 'y':或if answer in ('y', 'Y'): -
是的,这是正确的方法。
-
如果是错误的方式......你会得到不起作用的行为或堆栈跟踪的错误消息。你有得到吗?如果不是 - 为什么要问?这是教程 - 材料:docs.python.org/3/tutorial/controlflow.html#if-statements - 这不是 SO 的问题。
-
完全不相关,但
raw_input()将始终返回一个字符串。
标签: python string if-statement operator-keyword