CONDITIONALSTATEMENT
ITERATIVE STATEMENT
1. EMPTY STATEMENTS
Syntax: Pass
2. SIMPLE STATEMENT
EXAMPLE: >>>
3. COMPOUND STATEMENT-
PATTERN:
STATEMENT
FLOW CONTROL
Sequence-
THE SEQUENCE CONTRUCT
SELECTION-
THE SELECTION CONSTRUCT
ITERATION (LOOPING) –
The Iteration construct
PROGRAM LOGIC DEVELOPMENT
TOOLS
EXAMPLE:
ALGORITHM
IF STATEMENT OF PYTHON
Syntax :
Example :
print(“num is less than 200”)
If else statement
Syntax:
Example:
print (“even number”)
print (“odd number”)
IF – ELIF STATEMENT
Syntax:
Example of if - elif statement:
EXAMPLE 1-
print (“batsman scored a century”)
print (“batsman scored a fifty”)
print (“batsman has neither scored a century nor
fifty”)
EXAMPLE 2-
“ is a negative number .”)
print “ is equal to zero .”)
print “ is a positive number .”
NESTED IF STATEMENT
FORM 1
(If inside if’s body)
if <conditional
expression>:
if <conditional
expression>:
Statement (s)
else :
Statement (s)
elif<conditional
expression>:
Statement
[statements]
else:
Statement
[statements]
FORM 2
(If inside elif’s body)
if <conditional
expression >:
Statement
[statements]
elif <conditional
expression >:
if <conditional
expression>:
Statement (s)
else :
Statement (s)
else :
Statement
[statements]
FORM 3
(If inside else’s body)
if <conditional
expression>:
Statement
[statements]
elif <conditional
expression>:
Statement
[statements]
else :
if <conditional
expression>:
Statement (s)
else :
Statement (s)
FORM 4
(If inside if’s as well as
else’s or elif’s body, i.e.,
multiple ifs inside)
if <conditional
expression>:
if <conditional
expression>:
Statement(s)
else:
Statement(s)
elif <conditional
expression>:
if <conditional
expression>:
Statement(s)
else :
Statement (s)
else :
if <conditional
expression>:
Statement (s)
else :
Statement (s)
EXAMPLE :
print(“A grade
print(“B grade”)
print (“C grade”)
print(“D grade”)
print(“Failing grade”)
RANGE () FUNCTION
Range (<lower limit >, <upper limit>)
#both limits should be integers .
EXAMPLE :
ITERATION / LOOPING STATEMENTS
counting loops
conditional loops
FOR LOOP
EXAMPLE:1
Loop through string
–
name = ‘UMIYA’
For C in name :
print (C)
Output :
U
M
I
Y
A
EXAMPLE : 2
Loop through list-
mylist = (10,20,30,40,50)
For i in mylist:
print (i)
Output :
10
20
30
40
50
EXAMPLE : 3
Sum of any 5 natural
numbers through for loop -
sum = 0
For x in range (1,6) :
num = int
(input(“Enter a num” : 3))
Sum = sum + num
print (Sum)
Output : 3
EXAMPLE : 4
Through body of
for loop-
For a in [1,4,7]:
print (a)
print (a*a)
Output :
1
1
4
16
7
49
WHILE LOOP
Example 1:
print the value of i as long as i
is less than 6 :
i = 1
while i < 6 :
print (i)
i += 1
Output :
1
2
3
4
5
Example 2 :
Print the squares of all
integers from 1 to 10.
i = 1
while i <= 10 :
print (i ** 2)
i += 1
Output :
1
4
9
16
25
Example 3 :
While loop with else.
while (3>4)
print (“in the loop”)
else :
print (“exiting from
while loop”)
36
49
64
81
100
JUMP STATEMENT – BREAK AND
CONTINUE
BREAK STATEMENT
Example :
Break
print
print (“The end”
CONTINUE STATEMENT
Example :
Continue
print (‘ out of loop’)
NESTED LOOPS
Example :
print (“ * ” ‘ ’
print
TEXT YOURSELF
QUES . 1
QUES. 2
QUES . 3
QUES. 4
QUES. 5
QUES. 6
Python statements

Python statements