Now in the above example we want to print "Greater than" if the number is greater than 100. For that we have to use the
else statement. This works when the
ifstatement is not fulfilled.
#!/usr/bin/env python
number = int(raw_input("Enter a number: "))
if number < 100:
print "The number is less than 100"
else:
print "The number is greater than 100"
$ ./number100.py
Enter a number: 345
The number is greater than 100
Another very basic example
>>> x = int(raw_input("Please enter an integer: "))
>>> if x < 0:
... x = 0
... print 'Negative changed to zero'
... elif x == 0:
... print 'Zero'
... elif x == 1:
... print 'Single'
... else:
... print 'More'