Reputation: 1
magicnumber = 2000 ;
for x in range(10000):
if x is magicnumber:
print(x,"Is the Magic Number")
break
I need assistance.
Upvotes: 0
Views: 55
Reputation: 21
magicnumber = 2000
for x in range(10000):
if x == magicnumber:
print(x,"Is the Magic Number")
break
Upvotes: 1
Reputation: 17074
You need to replace is
with ==
. And you need to read this for more understanding: 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
Output:
(2000, 'Is the Magic Number')
Upvotes: 4
Reputation: 48287
if x is magicnumber:
is the same as
if x is 2000:
which returns false, therefore that condition is never met
if x == magicnumber:
is what you are looking for...
Upvotes: 1