0% found this document useful (0 votes)
2 views17 pages

Python Loops and Conditionals Lesson

This document outlines a lesson plan for teaching Python programming, focusing on loops and conditional statements. Students will learn to identify and use for and while loops, the range() function, and if statements to create programs that automate tasks and make decisions. The lesson includes exercises and real-life examples to illustrate the concepts, culminating in a summary and exit ticket questions for assessment.

Uploaded by

Abdallah A.5
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)
2 views17 pages

Python Loops and Conditionals Lesson

This document outlines a lesson plan for teaching Python programming, focusing on loops and conditional statements. Students will learn to identify and use for and while loops, the range() function, and if statements to create programs that automate tasks and make decisions. The lesson includes exercises and real-life examples to illustrate the concepts, culminating in a summary and exit ticket questions for assessment.

Uploaded by

Abdallah A.5
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

Unit 1 Lesson 1: python Day : Monday

LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025


Value of the month : Respect

Introduction for python

Learning Objectives
By the end of the lesson, students will be able to:
[Link] and describe the purpose of for and while loops.
[Link] how the range() function controls the iteration of a loop.
[Link] simple programs using if statements to make decisions.
[Link] loops and conditional statements to create more complex
and useful programs.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

•Keywords:

• Loop: A sequence of instructions that is repeated.


• For Loop: Repeats a set number of times.
• While Loop: Repeats as long as a condition is true.
• Conditional Statement: Code that runs only if a specific
condition is met.
• If/Else: A type of conditional statement.
• Range(): A function that generates a sequence of
numbers.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

BIG QUESTION: Warm-up


activity 3 minutes

HOW CAN WE USE PROGRAMMING TO AUTOMATE REPETITIVE TASKS


AND MAKE DECISIONS FOR US?
We can use loops and conditional statements in programming to automate repetitive tasks and make
decisions.
Loops automate repetitive tasks by allowing a block of code to run multiple times without having to
write it out over and over.

•A for loop is used when you know exactly how many times you want to repeat a task.
•A while loop is used to repeat a task as long as a certain condition is true.

Conditional statements, such as if/else, enable programs to make decisions by checking if a condition
is met.
The program then executes a specific action based on whether the condition is true or false.
By combining loops and conditionals, you can create powerful programs that not only perform tasks
repeatedly but also adapt their behavior based on specific circumstances.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

REAL LIFE EXAMPLES :

How is a traffic light like a computer


program?

A traffic light is like a computer program because it


follows a loop. It repeats the same sequence of
actions—changing from green to yellow to red—over
and over again. This is similar to how a computer
program uses a loop to perform a repetitive task.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

NATIONAL IDENTITY & SDG:

The country uses technology and automation to


build "smart cities" that manage resources efficiently.
For example, a system that automatically turns off
lights in a building when no one is in a room.
This uses if statements (if a person is in the room, keep
the lights on; else, turn them off).
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

•For Loop & range(): loop is used when you know exactly how many times you want to repeat
something. The range() function is a perfect partner for this.

•Example: for i in range(5): print("Hello") This will print "Hello" exactly five times.
•Explain the syntax: for is the keyword, i is a temporary variable, in is a keyword, and range(5) is
the sequence.

•If Statement: if statement allows a program to make a decision. It checks if a condition is true or
false.

•Example: if temperature > 30: print("It's hot outside!"). Explain that > is a comparison operator.

•Combining them: Show how loops and conditionals work together to create more powerful
programs.

•Example: for i in range(1, 11): if i % 2 == 0: print(i)


•This program will print all the even numbers from 1 to 10. Explain the % (modulo) operator as a
way to find the remainder of a division.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXERCISE 1

Examine the Python program on the right.


Create a loop that repeats a block of code a specific number of times. In this
[Link] "for" command is used to: ____________________________________
case, it will repeat the commands on lines 2 and 3 five times.

There are 3 variables used. They are i, name, and grade.


[Link] many variables are used? List them._____________________________
The commands are repeated 5 times, as specified by the range(5)
[Link] many times are the commands on lines 2function.
and 3 repeated?____________________________
The range(5) function generates a sequence of numbers from
0 to 4.
[Link] is "float" used on line 3?___________________________________________
The float() function is used to convert the input string for the grade into a floating-point
number. This allows the program to handle grades that are not whole numbers, such as
95.5 or 88.75.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXERCISE 1

Try the program on your computer. Modify it in order to accept 2 grades for each student and
then to calculate and display their average.
To accept two grades and calculate the average, you can modify the loop to ask for a second
grade and then compute the average inside the loop.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXERCISE 1

Once the program is running correctly, modify it in order to create a global variable named
"total" to calculate and display the average of all the students.

To calculate the average of all students, you need to initialize a variable outside the loop to
keep a running total. This is a global variable in this context. You then add each student's
average to this total and calculate the final class average after the loop has finished.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXERCISE 2: Examine the Python programs below and describe their utilities.

The first program will display


•This program uses a for loop and the range() function to iterate
through a sequence of numbers. The range(5, 10) function starts at
the number 5 and goes up to, but does not include, the number 10.
•Output: The program will print the numbers 5, 6, 7, 8, and 9 on
separate lines.

The second program will display

•Explanation: This program uses a for loop to iterate through the


numbers from -3 up to, but not including, 7. Inside the loop, it
multiplies each number i by 2 and then prints the result.
•Output: The program will print the following sequence of
numbers: -6, -4, -2, 0, 2, 4, 6, 8, 10, 12.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXERCISE 2: Examine the Python programs below and describe their utilities.

The third program will display

will generate a sequence of numbers starting at 4,


stopping before 17, and increasing by a step of 3. The
values for i will be 4, 7, 10, 13, 16.

The fourth program will display

will generate a sequence of numbers in reverse. The


values for i will be 30, 25, 20, 15, 10, 5.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

•Describe the utility of this program.

This program calculates the net price of a


product based on its origin (Local or Imported)
and its price. It applies a different discount rate
depending on both criteria. The program uses a
nested if/else structure to determine the final
price after the discount is applied.

•Name the variables used.

•The variables used in the program are


origin, price, and net.
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

•How many times will the program run the instructions


between lines 3 and 13?
The instructions between lines 3 and 13 will run
once. The program doesn't contain a loop, so
the code block is executed a single time for
each run of the program.
•What happens if the user types the letter "R"?

If the user types "R", the program will first check the
condition on line 3 (if origin=="L"), which will be False. It will
then proceed to the else block on line 8. Inside this block,
the program will execute the if statement on line 9, which
will be True if the price is greater than 1000, or False
otherwise. It will then calculate the net price and print the
result. The program will not recognize "R" as a valid origin,
but it will still execute without an error because the else
block on line 8 is a catch-all for any input that isn't "L".
Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

•Modify the program above as shown.

•Test it and write down the improvement made.


Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

CHALLENGING QUESTION

Modify the program above as shown.

Test it and write down the improvement made.


Unit 1 Lesson 1: python Day : Monday
LO: 1. Reviewing the skills learned in grade11 Date : 8/9/2025
Value of the month : Respect

EXIT TICKET & SUMMARY


•Summary Points:
•Loops help us repeat tasks.
•THE FOR LOOP is for a known number of repetitions.
•THE WHILE LOOP is for when the number of repetitions is unknown (e.g., until a condition is
met).
•Conditional statements like if/else allow our programs to make decisions.
•We can combine loops and conditionals to create sophisticated programs that automate complex
tasks.

•Exit Ticket:
•Have students answer the following questions :

[Link] is the main difference between a for loop and a while loop?
[Link] one example of a real-life problem you could solve with a conditional statement.

You might also like