【发布时间】:2017-10-31 08:26:08
【问题描述】:
我没有通过这个 Python 代码得到想要的结果。需要帮助。
当您输入符合条件的字符串时,while 循环应该停止。
代码:
x = input("Enter input: ")
while (int(x[3]) != 1 or int(x[3]) != 2):
print("The fourth character must be a 1 or 2")
x = input("Enter input again: ")
【问题讨论】:
-
看起来
or应该是and。 -
您输入的任何数字将始终不等于 1 或 2,因此条件始终成功。
标签: python string loops while-loop boolean