0% found this document useful (0 votes)
8 views4 pages

Sample Loops in Python Chapter

This document introduces loops in Python, explaining their purpose and importance in programming for repeating tasks efficiently. It covers the for loop syntax, the range() function, and provides examples and classroom activities to illustrate the concept. Additionally, it includes multiple choice and true/false questions to reinforce learning outcomes.

Uploaded by

Steven Khristi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Sample Loops in Python Chapter

This document introduces loops in Python, explaining their purpose and importance in programming for repeating tasks efficiently. It covers the for loop syntax, the range() function, and provides examples and classroom activities to illustrate the concept. Additionally, it includes multiple choice and true/false questions to reinforce learning outcomes.

Uploaded by

Steven Khristi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Loops in Python

Sample Chapter for Publisher Submission

Introduction
Have you ever been asked to write the same sentence again and again? It can become tiring
and boring after some time. Computers also face situations where a task needs to be
repeated multiple times. Instead of writing the same instruction again and again,
programmers use something called a loop.

A loop helps the computer repeat a task quickly, accurately, and without getting tired. Loops
are used in games, mobile apps, washing machines, traffic lights, and many other
technologies around us.

Learning Outcomes
• Understand the concept of repetition in programming.
• Explain the need for loops in Python.
• Use the for loop correctly.
• Understand the purpose of the range() function.
• Predict the output of simple programs.
• Write basic Python programs using loops.

Think and Discuss


Look around your daily life. Brushing your teeth, climbing stairs, doing exercise repetitions,
or practising cricket shots — all these activities involve repetition.

Computers also repeat actions in a similar way. In programming, this repetition is called
looping.

What is a Loop?
A loop is a programming structure that repeats a set of instructions multiple times.

For example, if we want the computer to display a message 10 times, we do not need to
write the same statement repeatedly. A loop can do this work automatically.

The for Loop in Python


The for loop is used when we know how many times we want to repeat a task.

Syntax:

for variable in range(number):


statement
Example Program
Program:

for i in range(5):
print('Welcome')

Output:
Welcome
Welcome
Welcome
Welcome
Welcome

Understanding range()
The range() function controls how many times the loop will run.

Example:
range(5)

This generates:
0, 1, 2, 3, 4

Python starts counting from 0 by default.

Classroom Activity
Activity: Act Out the Loop

1. One student walks around a chair 5 times.


2. Another student counts loudly.
3. The class observes carefully.

Discussion Questions:
- What action repeated?
- What changed each time?
- Why did the student stop?

This activity helps students understand how loops repeat actions based on instructions.

Real-Life Applications of Loops


• Video games for repeating animations
• Traffic signals for changing lights continuously
• Fitness apps for counting steps
• Washing machines for repeating wash cycles
• Alarm clocks for repeated ringing

Important Points to Remember


• A loop repeats instructions automatically.
• The for loop is used for fixed repetitions.
• range() controls repetitions.
• Indentation is important in Python.
• Python starts counting from 0.

Multiple Choice Questions


1. Which keyword is used to create a loop in Python?

• a) print
• b) loop
• c) for
• d) repeat

Answer: c) for

2. What does range(5) generate?

• a) 1 to 5
• b) 0 to 4
• c) 0 to 5
• d) 1 to 4

Answer: b) 0 to 4

3. Which function displays output on the screen?

• a) input()
• b) print()
• c) show()
• d) output()

Answer: b) print()

True or False
• A loop helps reduce repeated writing. — True
• range(5) includes the number 5. — False
• Python starts counting from 0. — True
• Indentation is not important in Python. — False

Answer the Following Questions


What is a loop?
A loop is a programming structure used to repeat instructions multiple times automatically.

Why do programmers use loops?

Programmers use loops to save time and avoid writing the same instruction repeatedly.

What is the purpose of range()?

The range() function controls how many times a loop should run.

You might also like