0
magicnumber = 2000 ;

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

I need assistance.

help-info.de
  • 6,695
  • 16
  • 39
  • 41
  • 2
    Welcome to Stack Overflow! Please go through the [tour](http://stackoverflow.com/tour), the [help center](http://stackoverflow.com/help) and the [how to ask a good question](http://stackoverflow.com/help/how-to-ask) sections to see how this site works and to help you improve your current and future questions, which can help you get better answers. – help-info.de Feb 05 '17 at 09:21

3 Answers3

4

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')
Community
  • 1
  • 1
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
1
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...

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
1
magicnumber = 2000

for x in range(10000):
    if x == magicnumber:
        print(x,"Is the Magic Number")
        break
Mohammad Yusuf
  • 16,554
  • 10
  • 50
  • 78
Vikrant
  • 21
  • 2