Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

IEC 2015 - Python Programming

Week 7 - While loops


While loops

Lesson Plan

We introduced ‘while’ loops as a way of repeating the students’ guessing game for a
set number of tries. We chose to go with ‘while’ rather than ‘for’ because we felt that
Python’s implementation of ‘for’ was not as intuitive as ‘while’ implementation.

We explained the use of while loops on the board and gave them the worksheet
below for them to test and try.

Teaching challenges:

This class was in a way a test of how well our lessons were getting across to the
students. There was a clear difference perceivable between the students who
understood programming so far, and the students who were merely following
directions.
IEC 2015 - Python Programming
Week 7 - While loops
Worksheet
(1) We count from 5 -> 1

print('Please type your name')


name = input()

print('Hello ' + name)

count = 5

while count > 0:


print(count*name)
count = count - 1

Output of this would be:

Please type your name


Dave
Hello Dave
DaveDaveDaveDaveDave  While loop starts here
DaveDaveDaveDave
DaveDaveDave
DaveDave
Dave  And ends here

(2) We count from 1 -> 5

print('Please type your name')


name = input()

print('Hello ' + name)

count = 0

while count <= 5:


print(count*name)
count = count - 1
IEC 2015 - Python Programming
Week 7 - While loops
**IMPORTANT**

When writing loops (‘while’) or conditionals (‘if’’ ,‘else’) -

1) There should be “:” at the end of that statement.


Example: while count <= 5:
if guess == number:
2) The next statement should begin with some ‘space’ before words.

Example:
while count <= 5:
_______count = count + 1

Another example:
if guess == number:
_______print(‘Correct guess’)

What will be the output of this program?


print('Please type your name')
name = input()

print('Hello ' + name)

count = 5

while count > 0:


count = count - 1
print(count*name)

print(‘Bye!’)

You might also like