You are on page 1of 114

Agenda

Statements
Types of Statements
Empty Statement
Simple Statement
Compound Statement
Control Flow
Statement Flow Control
Sequence
Selection
Real life Examples
Iteration/Looping Statement
Iteration
Flow Charts
IF Statements of Python
The if Statement
Syntax of if Statement
Interesting Facts…
Interesting Facts…
if Statement
Example
if – else statement
Syntax of if – else statement
if – else statement
Example
Check number is Even or Odd
if – elif statement
Syntax of if – elif statement
if – elif statement
Example
Nested - if statement
Syntax of Nested - if statement
Example
WAP to check entered number is positive
or negative.
WAP to find greater among 3 numbers.
Looping / Iteration
Iteration
while loop
while loop
Anatomy of while loop
Anatomy of while loop
1. 2.

4.

3.
Syntax of while loop
Example
Infinite Loop / Endless Loop
Example
Example
Caution
range() function
Syntax
Examples

10,8,6,4,2
for i in range(7,2,-3)
print(i)

for i in range(7,0,-3)
print(i)
for loop

Syntax of for loop


Execution in for loop
Example of range( )

Start = 0 (by Default)


Stop = 5 (not included)
Step = 1 (by Default)
Example of range( )

Start = 2
Stop = 10 (not included)
Step = 1 (by Default)
Example of range( )

Start = 2
Stop = 21 (not included)
Step = 2 (by Default)
Example of range( )
Example of range( )
Nested Loop
Syntax of Nested for Loop
Example
Execution
Print Multiplication Table
Print Multiplication Table
21
Find the 31
32
output… 41
42
43
for a in range(2,7): 51
52
for b in range(1,a): 53
54
print(a , b) 61
62
63
64
65
Find the output…
0
0123456789
for i in range(5): 1
0123456789
print(i)
2
for j in range(10): 0123456789
print(j, end = " ") 3
print() 0123456789
4
0123456789
Find the output…
for a in range(2,7):
for b in range(1,a):
print('#', end = " ")
print()
#
##
###
####
#####
Find the output…
for i in range(1,6):
for j in range(1,i+1):
print(j, end = " ")
print()
1
12
123
1234
12345
Find the output…
for i in range(5,0,-1):
for j in range(i,0,-1):
print(j, end = " ")
print()
54321
4321
321
21
1
Find the output…
for i in range(2,11):
print("\n Table of ", i)
for j in range(1,11):
print(i,'x',j,'=',i*j)
Practice
Questions
Jump Statements
break Statement
Syntax (break Statement in while Loop)
Example of break Statement
The continue Statement
Syntax (continue Statement in for loop)
Example
Difference between break and continue
Loop else statement
Syntax
Example
Example

You might also like