Since you use raw_input , you get a value like String, which is always considered to be greater than 0 (even if String has a value of "-10")
Instead, try using input('Enter a number: ') and python will do the type conversion for you.
The final code would look like this:
a = input('Enter a number: ') if a > 0: print 'Positive' elif a == 0: print 'Null' elif a < 0: print 'Negative'
However, as a number of people have pointed out, using input () can lead to an error, since it actually interprets the python objects passed to.
A safer way to handle this could be to reset the raw_input with the required type, as in:
a = int (raw_input ('Enter a number:'))
But be careful, you still have to make some mistakes to avoid trouble!
source share