[go: up one dir, main page]

0% found this document useful (0 votes)
72 views3 pages

While Loops Lesson Plan

The document discusses using while loops in Python programming lessons. It introduces while loops as a way to repeat a guessing game for a set number of tries. It explains that while loops were used instead of for loops because the implementation of for loops in Python is less intuitive than while loops. It includes sample code for two while loop examples - one that counts down from 5 to 1 and one that counts up from 1 to 5. It highlights important syntax rules for writing while and if/else conditional statements in Python. It also provides sample code and asks what the output would be.

Uploaded by

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

While Loops Lesson Plan

The document discusses using while loops in Python programming lessons. It introduces while loops as a way to repeat a guessing game for a set number of tries. It explains that while loops were used instead of for loops because the implementation of for loops in Python is less intuitive than while loops. It includes sample code for two while loop examples - one that counts down from 5 to 1 and one that counts up from 1 to 5. It highlights important syntax rules for writing while and if/else conditional statements in Python. It also provides sample code and asks what the output would be.

Uploaded by

Dlanor Nablag
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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