0

This is quite possible the most perplexing piece of code I've ever seen, and i can't seem to figure out what's wrong with it.

a = 5
if a == 0 or 1 : 
    print "hi"

When run, it prints "hi" which by all means confuses me. Please provide some insight onto how i can make it not return hi and behave normally. (it should be returning nothing)

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
john hon
  • 103
  • 2
  • 2
  • 7

2 Answers2

0
a = 5
if (a == 0) or (a == 1): #changed from if a == 0 or 1
    print ("hi")
#does not print 'hi'

Check a against 0 and 1 independently.

Rafael
  • 3,096
  • 1
  • 23
  • 61
0

It should work in this way:

  while not a = 5:
          if a in [0, 1]:
              print "Hi"
Kian
  • 1,319
  • 1
  • 13
  • 23