【发布时间】:2016-01-31 22:31:20
【问题描述】:
我对 Python 比较陌生,我不明白以下代码会产生随后的意外输出:
x = input("6 divided by 2 is")
while x != 3:
print("Incorrect. Please try again.")
x = input("6 divided by 2 is")
print(x)
其输出为:
6 divided by 2 is 3
Incorrect. Please try again.
6 divided by 2 is 3
3
Incorrect. Please try again.
6 divided by 2 is
为什么即使 x 等于 3,while 循环仍在执行?
【问题讨论】:
标签: python loops while-loop