【发布时间】:2018-02-03 04:20:59
【问题描述】:
我正在尝试将代码从 Python 2.7.10 切换到 Python 3,但有些东西不起作用。我最近才被介绍给 Python。
choice = 2
while choice != 1 and choice != 0:
choice = input("Hello, no.")
if choice != 1 and choice != 0:
print("Not a good code.")
如何将“!=”更改为 Python 3 可以理解的内容?当我输入 1 或 0 时,它给了我“你好,不”的无效打印。
【问题讨论】:
-
首先,学会缩进你的代码。其次,Python3 中的
input返回一个字符串。在比较之前,您必须将其转换为int。第三,您可能会发现此文档很有用:docs.python.org/3/howto/pyporting.html -
@DYZ:这看起来与这个问题相反......
-
choices = 2choice=str(choices) whilechoice != '1' 和choice != '0':choice = input("Hello, no.") ifchoice != '1'和选择!='0':打印(“不是一个好的代码。”)
标签: python python-3.x