In a make task you use the skills you have learned to create a program from scratch. There is no starter code: you begin with an empty editor.
You are going to write the login check that guards a website. It asks for a username and a password, and it refuses to let go until the password is right.
abc123 in a variable with a sensible name. It is fixed:
your program never changes it.while loop that keeps going for as long as the password the user
entered is not abc123. Inside the loop, ask for the password again, so that
the user gets another chance and the condition can change.Login accepted.Ask each question with its own print, and read the answer with a bare
input() on the next line. Ask them with exactly this wording:
Enter your username:
Enter your password:
Every question is printed exactly as written above, so your program’s output
is not just Login accepted: it is the username question, the password
question, one more password question for every wrong attempt, and finally the
acceptance message. For example, with one wrong attempt before the right
password:
Enter your username:
Enter your password:
Enter your password:
Login accepted
A wrong password otherwise produces no extra output of its own: the user simply gets asked again, and nothing but the repeated question appears until the password is right.
Input:
Ben
abc123
Output:
Enter your username:
Enter your password:
Login accepted
The next example gets the password wrong three times before getting it right. The first line is still the username, and every line after it is an attempt at the password:
Input:
Dev
123abc
ABC123
abcd123
abc123
Output:
Enter your username:
Enter your password:
Enter your password:
Enter your password:
Enter your password:
Login accepted
The password is compared with !=, so the match has to be exact. ABC123 is
not abc123, and neither is abc1234, so both of those count as wrong
attempts.
The two questions are part of the output that is checked here, so their
spelling, capital letters and punctuation count. Ask each one with its own
print, exactly Enter your username: and Enter your password:, and read
the answer with a bare input() on the next line, rather than passing the
question to input(...).
Make sure that you check for the following things:
while.while line has a condition.while line has a colon (:) at the end.while, and all of
it by the same amount. Never mix tabs and spaces in one file.Login accepted is printed once rather than every time round the loop.input line inside the loop as well
as before it. Without them the user never gets another chance to type, so the
condition can never change and the loop never ends.abc123 is spelled exactly that way, in speech marks, everywhere
it appears.