magicnumber = 2000 ;
for x in range(10000):
if x is magicnumber:
print(x,"Is the Magic Number")
break
我需要帮助。
答案 0 :(得分:4)
您需要将is
替换为==
。您需要阅读本文以获得更多理解:Is there a difference between `==` and `is` in Python?
magicnumber = 2000 ;
for x in range(10000):
if x == magicnumber:
print(x,"Is the Magic Number")
break
输出:
(2000, 'Is the Magic Number')
答案 1 :(得分:1)
if x is magicnumber:
与
相同if x is 2000:
返回false,因此永远不会满足该条件
if x == magicnumber:
正是你要找的......
答案 2 :(得分:1)
magicnumber = 2000
for x in range(10000):
if x == magicnumber:
print(x,"Is the Magic Number")
break