You are on page 1of 4

Flow of Control

Type of statements in Python


 Empty statement(null statement)
The simple statement is the empty statement i.e., a statement which does
nothing. The pass statement is used in python for empty statement.

 Simple statement(single statement)


Any single executable statement is a simple statement in python.
Example:
print(“ops, ranchi”)
A=int(input(“enter a numbr’))

 Compound statement
A compound statement represents a group of statements executed as a unit.
<compound statement header>: # begins with keyword and end with a colon(:)

body # python statements


indentation

if marks>=33: # header
print (" pass ")#body

DECISION -MAKING
There are four types of decision-making statements in python:
• if statement
• if –else statement
• if- elif-else statement
• nested if –else statement

Decision–making statements are used to control the flow of execution of


program depending upon condition.
if statement: if the condition is true, then the body statement gets
execute.
Syntax: if condition: Example:
statement(s)
statement(s) marks=int(input(" enter marks "))
if marks>=33:
print (" pass ")

if –else statement: if statements are execute only if condition is true,


otherwise statement following else will be execute.

Syntax: Example:
n=int(input(" enter integer number"))
If condition:
if n%2==0:
statement(s) print(" even number ")
else: else:
statement(s) print(" odd number ")

Example:
age=int(input("enter your age "))
if age>=18:
print(" Eligible to vote ")
else:print(" Not eligible to vote ")
if – elif-else statement: it is used in the situations where a user can
decide among multiple options. If any condition is true, then the
statements associated with that if are executed and rest of the condition
is bypassed. If none of the conditions is true, then the else statement will
be execute.

Syntax:
if condition:
statement(s)
elif condition:
statement(s)
elif condition:
statement(s)
else:
statement(s)

#example: a program to accept percentage and display result


per=float(input(" enter marks percentage "))
if per>=60:
print(" First Div ")
elif per> = 45 and per < 60:
print(" Second Div ")
elif per>=33 and per < 45:
print(" Third Div ")
else:
print(“fail”)
nested if – else statement: if –else statement inside another if –else
statement is called nested .

Syntax:
if condition:
if condition:
statement(s)
else:
statement(s)
else:
statement(s)

#example: to check whether a number is positive or negative


num=float(input(" enter a number"))
If num>=0:
if num==0:
print("zero")
else:
print("Positive Number")
else:
print("Negative Number")

You might also like