Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

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

 

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]