Curriculum
Course: Grade XI Informatics Practices
Login
Text lesson

Ch3-Control-Flow-in-Python

School Revise · Class 11 Informatics Practices · Chapter 3

Control Flow in Python

Code 065, Class 11. Programs make choices and repeat work. Here we use if for decisions and for and while loops for repetition.

2

kinds of loop

3

if, elif, else

What this chapter is about

By default Python runs top to bottom. if makes decisions and loops repeat work. This is the flow of control.

1. Decisions with if

An if runs a block when a condition is True; elif checks another; else runs when none are. Indent the block by four spaces.

n = 8 if n % 2 == 0: print(“even”) else: print(“odd”) Output: even

2. The for loop

for repeats over a range. range(1, 6) gives 1, 2, 3, 4, 5.

3. The while loop

while repeats while a condition is True. Change something inside so it can end. break stops a loop, continue skips to the next round.

Practise with the interactive

Explore the idea by tapping. The interactive opens right here in the lesson.

Try it in the code lab

Write and run real Python right here in the lesson, then work through the practice problems with answers.

Starting Python...

Coding practice problems, with answers

Type each one into the code lab above, then open the card to see the worked solution and its output.

Problem 1. Print whether 8 is even or odd.

SOLUTION

n = 8 if n % 2 == 0: print(“even”) else: print(“odd”)

OUTPUT

even
Problem 2. Print the larger of 5 and 9.

SOLUTION

a, b = 5, 9 if a > b: print(a) else: print(b)

OUTPUT

9
Problem 3. Print the numbers 1 to 5.

SOLUTION

for i in range(1, 6): print(i)

OUTPUT

1 2 3 4 5
Problem 4. Print the 3 times table.

SOLUTION

for i in range(1, 11): print(3, “x”, i, “=”, 3 * i)

OUTPUT

3 x 1 = 3 … up to 3 x 10 = 30
Problem 5. Find the sum of 1 to 10.

SOLUTION

s = 0 for i in range(1, 11): s = s + i print(s)

OUTPUT

55
Problem 6. Count down from 5 with while.

SOLUTION

n = 5 while n > 0: print(n) n = n – 1

OUTPUT

5 4 3 2 1
Problem 7. Positive, negative or zero.

SOLUTION

n = -4 if n > 0: print(“positive”) elif n < 0: print(“negative”) else: print(“zero”)

OUTPUT

negative
Problem 8. Print even numbers 2 to 10.

SOLUTION

for i in range(2, 11, 2): print(i)

OUTPUT

2 4 6 8 10
Problem 9. Find the factorial of 5.

SOLUTION

f = 1 for i in range(1, 6): f = f * i print(f)

OUTPUT

120
Problem 10. Print a triangle of stars.

SOLUTION

for i in range(1, 5): print(“*” * i)

OUTPUT

* ** *** ****

Practice set A, multiple choice

1. Which loop repeats while a condition is True?

while.

2. range(1, 6) gives?

1, 2, 3, 4, 5.

3. Which runs when no if or elif is True?

else.

4. Which stops a loop early?

break.

Quick summary

if (with elif and else) makes decisions; a for loop repeats over a range (range(1, n) stops before n); a while loop repeats while a condition is True. break stops a loop and continue skips a round. Indent blocks by four spaces.

Open the Virtual Lab

These free Class 11 Informatics Practices notes explain control flow, if elif and else, for and while loops, range, break and continue with worked examples and practice, for CBSE students across India and the Gulf including the UAE, Saudi Arabia, Qatar, Oman, Kuwait and Bahrain.

© 2026 School Revise. All rights reserved. Original content aligned to the CBSE and NCERT Class 11 Informatics Practices syllabus. Unauthorised copying is not permitted.

Layer 1
Login Categories