if Statements: if, elif and else : If « Language Basics « Python






if Statements: if, elif and else

if Statements: if, elif and else


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'



           
       








Related examples in the same category

1.Nested if statementNested if statement
2.if-else structureif-else structure
3.if-elif-else structureif-elif-else structure
4.if structureif structure
5.Boolean operation in ifBoolean operation in if
6.elif demoelif demo
7.if with elseif with else
8.If statement: a dictionary-based 'switch'If statement: a dictionary-based 'switch'
9.Leap Year checkerLeap Year checker