Flow of Control: Type of Statements in Python
Flow of Control: Type of Statements in Python
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(:)
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
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)
Syntax:
if condition:
if condition:
statement(s)
else:
statement(s)
else:
statement(s)