Session UNIT - II
(2025-26) Chapter - 5
Class – XI
BASICS OF PYTHON
(Control Statements)
Vinod Kumar Jatav
PGT (Computer Science)
PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
LEARNING OBJECTIVES
✓ CONTROL FLOW STATEMENTS
1. DECISION MAKING STATEMENTS
▪ IF
▪ IF – ELSE
▪ IF – ELIF- ELSE
▪ NESTED IF - ELSE
2. ITERATION STATEMENTS (LOOPS)
▪ WHILE
▪ FOR
▪ NESTED FOR
3. JUMP STATEMENTS
▪ BREAK
▪ CONTINUE
▪ PASS
26-09-2025 Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR 2
CONTROL STATEMENTS
✓ Control statements are used to control the flow of execution
depending upon the specified condition/logic.
✓ There are three types of control statements.
1. Decision Making Statements
2. Iteration Statements (Loops)
3. Jump Statements (break, continue, pass)
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 3
DECISION MAKING STATEMENTS
✓ Decision making statements are used to control the flow of
execution of program depending upon condition.
✓ There are four types of decision making statement.
1. if Statements
2. if-else Statements
3. Nested if-else Statements
4. if-elif-else Statements
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 4
DECISION MAKING STATEMENTS
1. if Statements - An if statement is a programming conditional
statement that, if proved true, performs a function or displays
information.
✓ Flow diagram: Syntax:
if (condition):
statement
[statements]
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 5
DECISION MAKING STATEMENTS
1. if Statements – Example 1:
no_books = int(input(‘Enter no. of books :’)) Output 1:
Enter no. of books : 2
if(no_books == 2): You have two books
print('You have two books’) outside of if statement
print(‘outside of if statement’)
Output 2:
Enter no. of books : 5
outside of if statement
➢ Note: To indicate a block of code in Python, you must indent each line of the
block by the same amount. In above e.g. both print statements are part of if
condition because of both are at same level indented but not the third print
statement.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 6
DECISION MAKING STATEMENTS
1. if Statements – Using logical operator in if statement
✓ Example 2:
x=1
y=2
if(x==1 and y==2):
print(‘condition matching the criteria')
Output:
condition matching the criteria
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 7
DECISION MAKING STATEMENTS
1. if Statements – Using logical operator in if statement
✓ Example 3:
a=100
If not(a == 20):
print('a is not equal to 20')
Output:
a is not equal to 20
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 8
DECISION MAKING STATEMENTS
2. if - else Statements - if-else statement executes some code if
the test expression is true (nonzero) and some other code if the
test expression is false.
✓ Flow diagram: Syntax:
if (condition):
statements else:
statements
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 9
DECISION MAKING STATEMENTS
2. if - else Statements – Example:
a=int(input(‘Enter any number : ’))
if(a < 100):
print(‘Number is less than 100')
else:
print(‘Number is more than or equal 100')
Output:
Enter any number : 10
Number is less than 100
➢ Home work: Write a program in python to check that
entered number is divisible by 7 or not?
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 10
DECISION MAKING STATEMENTS
3. if – elif- else Statements – The if-elif-else statement allows us
to check for multiple test expressions (more than 2 conditions).
a=int(input(‘Enter any number : ’)) Output 1:
if(a == 0): Enter any number : 234
print(‘Number is equal to Zero’) Number is a positive number
elif (a > 0):
print(‘Number is a positive number’)
Output 2:
else:
Enter any number : 0
print(‘Number is negative number ')
Number is equal to Zero
Output 2:
Enter any number : -50
Number is negative number
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 11
DECISION MAKING STATEMENTS
3. if – elif- else Statements
Home Work : Write a python program to take the marks of 5 subjects
(maximum marks =100 for each subject) from the user and display the grade as
per following criteria.
AVG Marks Grade
Avg >= 90 A
Avg >= 75 & avg < 90 B
Avg >= 60 & avg < 75 C
Avg >= 40 & avg < 60 D
Avg < 40 F
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 12
DECISION MAKING STATEMENTS
4. Nested if - else Statements - The nested if...else statement
allows you to check for multiple test expressions and execute
different codes for more than two conditions.
✓ Flow diagram: Syntax:
if (condition1):
if (condition2):
statements1
else:
statements2
else:
statements3
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 13
DECISION MAKING STATEMENTS
3. Nested if - else Statements – Example:
num= float(input("Enter a number: ")) # using if – elif- else
if num>= 0: num= int(input("Enter a number: "))
if num== 0: if (num == 0):
print("Zero") print("Zero")
else: elif (num > 0):
print("Positive number") print("Positive number")
else: else:
print("Negative number") print("Negative number")
Output:
Enter a number: 5
Positive number
➢ Home work: Write python program to find out largest of 3 numbers.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 14
DECISION MAKING STATEMENTS
3. if – elif- else Statements – Example:
num= int(input("Enter a number: "))
if (num == 0):
print("Zero")
elif (num > 0):
print("Positive number")
else:
print("Negative number")
Output:
Enter a number: 5
Positive number
➢ Home work: Write python program to find out largest of 3
numbers.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 15
ITERATION STATEMENTS (LOOPS)
✓ Iteration statements (loop) are used to execute a block of
statements as long as the condition is true.
✓ Loops statements are used when we need to run same code
again and again.
✓ Python Iteration (Loops) statements are of three type:-
1. while loop
2. for Loop
3. nested for loops
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 16
ITERATION STATEMENTS (LOOPS)
1. while Loop - It is used to execute a block of statement as long
as a given condition is true. And when the condition become
false, the control will come out of the loop.
✓ The condition is checked every time at the beginning of the
loop.
✓ Flow diagram: Syntax:
while(condition):
statement
[statements]
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 17
ITERATION STATEMENTS (LOOPS)
1. while Loop – Example 1:
Output:
x=1 1
while(x <= 4): 2
print(x) 3
x=x+1 4
▪ while Loop with else – Example 2:
x=1
while(x < 3):
Output:
print(‘Inside while loop x = ',x)
Inside while loop x = 1
x=x+1 Inside while loop x = 2
else: Inside else value of x is 3
print(‘Inside else value of x is ', x)
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 18
ITERATION STATEMENTS (LOOPS)
▪ Infinite while Loop – Example 3:
x=5
while (x == 5):
print(‘Inside loop')
Output:
Inside loop
Inside loop
Inside loop
………..
………..
………..
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 19
ITERATION STATEMENTS (LOOPS)
1. for Loop - It is used to iterate over items of any sequence,
such as a list or a string.
✓ Flow diagram: Syntax:
for loop
for val in sequence/range:
Test for range/ statements
sequence
for
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 20
ITERATION STATEMENTS (LOOPS)
2. for Loop – Example 1:
Output:
for i in range (3,5): 3
print(i) 4
▪ Example 2:
Output:
for i in range (5,3,-1): 5
4
print(i)
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 21
ITERATION STATEMENTS (LOOPS)
range() Function Parameters :
start: Starting number of the sequence.
stop: Generate numbers up to, but not including this number.
step(Optional): Determines the increment/decrement
between each numbers in the sequence.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 22
ITERATION STATEMENTS (LOOPS)
2. for Loop with else – Example 3:
for i in range(1, 4): Output:
print(i) 1
else: # Executed because no break in for 2
print("No Break") 3
No Break
3. Nested for Loop (for Loop within the for loop)
Example :
for i in range(1,3): Output:
1 2 3 4 5 6 7 8 9 10
for j in range(1,11):
2 4 6 8 10 12 14 16 18 20
k=i*j
print (k, end=‘ ') # end is used to avoid line change in output
print()
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 23
JUMP STATEMENTS
✓ Jump statements are used to transfer the program's control
from one location to another.
✓ Means these are used to alter the flow of a loop like-to skip a
part of a loop or terminate a loop.
✓ There are three types of jump statements used in python:-
1. break
2. continue
3. pass
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 24
JUMP STATEMENTS - BREAK
1. break - It is used to terminate the loop.
✓ Example:
for ch in "string":
if ch == 'r':
break Output:
else: s
t
print(ch)
Note: Here the for loop terminates as soon as the condition matches.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 25
JUMP STATEMENTS - CONTINUE
2. continue - It is used to skip all the remaining statements in the
loop and move controls back to the top of the loop.
✓ Example:
Output:
for ch in "string": s
t
if ch == "i": r
continue n
g
else:
print(ch)
Note: Here the for loop skips as soon as the condition matches.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 26
JUMP STATEMENTS - PASS
3. pass – This statement does nothing. It can be used when a
statement is required syntactically but the program requires no
action.
✓ Use in loop -
while True:
pass #Busy - wait for keyboard interrupt (Ctrl+C)
✓ Use in function – It makes a controller to pass by without
executing any code.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 27
JUMP STATEMENTS - PASS
▪ Example 1:
def myfun():
pass #if we don’t use pass here then error message will be shown
print(‘my program') Output:
my program
▪ Example 2:
for i in 'initial': Output:
if(i== 'i'): n
pass t
a
else: l
print(i)
Note: Continue forces the loop to start at the next iteration while pass means "there is no
code to execute here“ and will continue through the remainder or the loop body.
Vinod Kumar Jatav, PGT (Comp. Sc.), PM SHRI KENDRIYA VIDYALAYA NO1, UDAIPUR
26-09-2025 28
References:
• Computer Science with python - by Sumita Arora
• Computer Science with python - by Preeti Arora
• [Link]
• [Link]
29
Thank You!
30