understand that a block of code often needs to run more than once.
understand that a loop can be designed to run a block of code more than once.
understand that looping is known as iterating ie repeating
understand that a loop can be controlled by a variable
understand pseudocode for a count-controlled loop
understand a basic for loop in Python.
Challenge
In a future world, a king called Jackson reigns. Anyone with the name Jackson is always greeted with maximum respect.
A computer program does the following 1000 times:
inputs a name
if the name is Jackson, it prints out a message 7 times: Oh Jackson, thou art light and sound!
Otherwise a message Hi name. is displayed and the user is asked to enter a secret password. If the password entered is correct, the system displays ENTER! otherwise the system displays NO STRANGERS ALLOWED!
the secret password is j@ck50n
Find ways to make your solution modular!
Talk to your classmates as you design your program. Do they have some ideas you could use?
Introduction to Iteration
count-controlled loops
Getting started
A Chef bakes cakes!
The recipe is quite tricky and involves a lot of stirring, mixing and baking!
Let's help the Chef bake cakes!
Copy the starter code into your IDE, open the Worksheet and follow the instructions.
For Loops in Python
This unit only looked at how to use range() function when implementing for loops in Python.
But it is worth looking at other ways to use this amazing programming tool.