Ratanga
Ratanga

Reputation: 1

Python failing to recognise number above 1000

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

Answers (3)

Vikrant
Vikrant

Reputation: 21

magicnumber = 2000

for x in range(10000):
    if x == magicnumber:
        print(x,"Is the Magic Number")
        break

Upvotes: 1

Mohammad Yusuf
Mohammad Yusuf

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

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

Related Questions