Python
Programming
Lesson 10 - Iteration
Task 1 - Password Checker
You need to create a program that asks the user to enter a password using the input command. It should keep doing this until it matches the password stored. When it does match it should say “Access Granted”. To the right is an example of how the program should work.
Use the success criteria below to help you:
Create a variable called password created and set to a password of your choice
Create a variable called answer created and set to blank (“”)
A WHILE loop that looks like:
while password != answer:
answer = input (“Enter your password: “)
Outside the loop, a message using the print command saying “Access Granted” when the loop is broken i.e. a match
Extension
Improve your program so that it keeps count on the number of attempts you have at guessing the password. When you guess the password it should display how many attempts it took you. An example of how it should be work can be seen to the right.
You will need to:
Define a variable called attempts at the start as an integer and set it to 0
Inside the loop add one to attempts (attempts = attempts + 1)
Improve the print message so it looks like the one above
Task 2 - Adding Numbers
You need to create a program asks the user to enter a number using the input command. It should continually do this and add the numbers together until they enter 0. When they enter 0 it will stop asking them to enter a number and display the total of the numbers. An example of how it should look when run is shown to the right.
Use the success criteria below to help you:
Variable called number created and set to -1 (so that the loop will actually start!)
Variable called total created and set to 0
A WHILE loop that repeats while the number variable is not equal to (!=) 0.
Inside the loop it should:
Use the input command to ask the user to “Enter a number to add, or type 0 to finish” and store the response in the number variable.
Add the number entered to the total (total = total + number)
Display a message saying what the total is so far
Outside the loop, code to display a message saying what the overall total is when finished.
Extension
Improve your program so that when the program finishes and gives the total it also says how many numbers have been entered. An example of this is shown to the right.
You need to:
Create a variable called entries before the loop
Inside the loop add one to entries (entries = entries + 1)
In the message after the loop improve it so it says how many numbers have been entered
Evidence point
Open the Assignment in Google Classroom called Student Evidence - L10 - Iteration.
Take a screenshot of your code for:
Task 1 - Password Checker
Task 2 - Adding Numbers
For each program click on Share and choose Link. Copy the link and paste it into the document, this means you can come back to it in future lessons.