In these tasks you have to use the skills learned in the previous exercises to create a new program based on the requirements below.
Write a program that:
- Assigns the password ‘abc123’ to a variable with a sensible identifier.
- Asks the user to input their username and password and stores them in two new variables.
- Loops until the user enters the password ‘abc123’.
- Prints ‘Login accepted’ when the user does enter ‘abc123’
EXTRA CHALLENGES – Add these features.
- The username entered is displayed as part of the ‘Login accepted’ message.
- The user gets an ‘Error, incorrect password’ message if they get the password wrong.
- The program keeps count of how many tries the user takes to get the password right. This number is printed out as part of the ‘Login successful’ message.
Help! My code doesn’t work
Make sure that you check for the following things:
- Iteration begins with
while
.
- The
while
line has a condition.
- The
while
line has a colon at the end.
-
All the code you want to repeat is indented after the
while
.
- Any code that should run once the loop has finished is not indented