Spot the Errors in Python Programming Lesson

Python Programming
January 2018
Lesson 1 of 10
Do Now in Pairs
Spot the errors in this program
How many errors can you find?
P
 
R 
I
 M M
Do Now in Pairs - Answer
Spot the errors in this program
How many errors can you find?
P
 
R 
I
 M M
Lesson objectives
In this lesson we look at the differences between for loops and
while loops
You will use a while loop to develop a menu to run a selection of
different Python programs
 
Looking back
- what did these programs do?
F
o
r
 
l
o
o
p
W
h
i
l
e
 
l
o
o
p
Two types of loops
What is the difference?
P
 
R I M M
For loops and while loops
C
o
u
n
t
 
C
o
n
t
r
o
l
l
e
d
:
 
u
s
e
d
 
t
o
 
r
e
p
e
a
t
 
a
 
g
r
o
u
p
 
o
f
 
s
t
a
t
e
m
e
n
t
s
 
a
 
s
e
t
n
u
m
b
e
r
 
o
f
 
t
i
m
e
s
 
 
a
 
f
o
r
 
l
o
o
p
 
i
s
 
a
n
 
e
x
a
m
p
l
e
.
C
o
n
d
i
t
i
o
n
 
C
o
n
t
r
o
l
l
e
d
:
 
u
s
e
d
 
t
o
 
r
e
p
e
a
t
 
a
 
g
r
o
u
p
 
o
f
 
s
t
a
t
e
m
e
n
t
s
u
n
t
i
l
 
a
 
c
o
n
d
i
t
i
o
n
 
i
s
 
m
e
t
 
 
a
 
w
h
i
l
e
 
l
o
o
p
 
i
s
 
a
n
 
e
x
a
m
p
l
e
.
Tasks in pairs
Work out what the program on the left
does – there is a lot going on!
Then download the program, run it a
few times, and answer the questions
P
 
R I M M
Answers
1.
How many times will this program repeat?
2.
What would happen if you entered “3” as a choice?
3.
Give an example of a count controlled loop used in this
program.
4.
Give an example of a condition controlled loop used in this
program.
P
 
R 
I
 M M
Programming
1.
Update the message function to allow the user to choose how many times they
would like their message to be repeated.
2.
Now extend the timetable program to enable a given number to be multiplied to
the power of the numbers 1 to 5 (see the example below). You will need to add
a new function and update the if statement to allow the user to choose the new
3
rd
 option. You can use the “**” exponent operator in your calculation.
P
 
R I 
M
 M
Review
Would you use a for loop or a while loop for these programs?
1.
To input 10 numbers
2.
To ask the user to enter names of their brothers and sisters
3.
To calculate the average of 7 numbers
4.
To input the names of a team of netball players
5.
To let the user enter their password until it is correct
Review - answers
Would you use a for loop or a while loop for these programs?
1.
To input 10 numbers
2.
To ask the user to enter names of their brothers and sisters
3.
To calculate the average of 7 numbers
4.
To input the names of a team of netball players
5.
To let the user enter their password until it is correct
while
for
for
while
for
Slide Note
Embed
Share

Analyze a program, find errors, and distinguish between for loops and while loops. Learn to develop a menu using a while loop to run different Python programs. Discover the difference between count-controlled and condition-controlled loops.

  • Python Programming
  • Error Detection
  • Loops
  • Menu Development
  • Programming Concepts

Uploaded on Feb 19, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Python Programming January 2018 Lesson 1 of 10

  2. PR I M M Do Now in Pairs Spot the errors in this program How many errors can you find?

  3. PR I M M Do Now in Pairs - Answer Spot the errors in this program How many errors can you find?

  4. Lesson objectives In this lesson we look at the differences between for loops and while loops You will use a while loop to develop a menu to run a selection of different Python programs

  5. Looking back - what did these programs do? PR I M M While loop For loop Two types of loops What is the difference?

  6. For loops and while loops Count Controlled: used to repeat a group of statements a set number of times a for loop is an example. Condition Controlled: used to repeat a group of statements until a condition is met a while loop is an example.

  7. PR I M M Tasks in pairs Work out what the program on the left does there is a lot going on! Then download the program, run it a few times, and answer the questions

  8. PR I M M Answers 1. How many times will this program repeat? 2. What would happen if you entered 3 as a choice? 3. Give an example of a count controlled loop used in this program. 4. Give an example of a condition controlled loop used in this program.

  9. PR I M M Programming 1. Update the message function to allow the user to choose how many times they would like their message to be repeated. 2. Now extend the timetable program to enable a given number to be multiplied to the power of the numbers 1 to 5 (see the example below). You will need to add a new function and update the if statement to allow the user to choose the new 3rdoption. You can use the ** exponent operator in your calculation.

  10. Review Would you use a for loop or a while loop for these programs? 1. To input 10 numbers 2. To ask the user to enter names of their brothers and sisters 3. To calculate the average of 7 numbers 4. To input the names of a team of netball players 5. To let the user enter their password until it is correct

  11. Review - answers Would you use a for loop or a while loop for these programs? 1. To input 10 numbers 2. To ask the user to enter names of their brothers and sisters 3. To calculate the average of 7 numbers 4. To input the names of a team of netball players 5. To let the user enter their password until it is correct for while for for while

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#