Product SiteDocumentation Site

5.2. Else പ്രസ്താവന

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"

ഔട്ട്പുട്ട്
   
[kd@kdlappy book]$ ./number100.py
Enter a number: 345
The number is greater than 100

മറ്റൊരു ചെറിയ ഉദാഹരണം

>>> 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'