Scripting >> Python >> Examples >> Control Flow >> How to use if else elif control flow

 

Example 1

ifcontrolflow.py


while True:
   x = int(raw_input("Enter an integer: "))
   if x == 0 :
      print("Zero, exiting")
      break
   elif x < 0:
      print("Negative integer")
   else:
      print("Positive integer")

 

 

Example 2

Read input, integer N between 1 and 20.
For all non-negative integer less than N, print the square of the integer

N=int( raw_input() )
if N>=1 and N<=20 :
   i=0
   while i<N :
      v=i*i
      i=i+1
      print v