Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

The login check from the previous exercise works, but it is not much use to whoever is typing. A wrong password only shows the question again, with no error message, so the user cannot tell the difference between a rejected attempt and a program that has frozen, and nobody ever finds out how many goes it took.

This exercise adds all three of the missing pieces: an error message, the username in the acceptance message, and a count of the attempts.

Your task

Start again from an empty editor, or from your solution to the previous exercise.

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:

The output

Both questions are printed exactly as written above, and the password question is printed again for every wrong attempt. Every wrong attempt also prints this line, so three wrong attempts print it three times:

Error, incorrect password

The last line of the output is the acceptance message. NAME stands for whatever the user typed as their username, and NUMBER for the number of attempts it took:

Login accepted, NAME. Number of attempts: NUMBER

Count the successful attempt as well, so a user who gets the password right straight away took 1 attempt, and a user who got it wrong three times before getting it right took 4.

Watch the punctuation in that line: a comma and a space after accepted, then a full stop and a space after the username, then a colon and a space before the number.

Example

Input:

Ben
abc123

Output:

Enter your username:
Enter your password:
Login accepted, Ben. Number of attempts: 1

This user gets it wrong three times first:

Input:

Dev
123abc
ABC123
abcd123
abc123

Output:

Enter your username:
Enter your password:
Error, incorrect password
Enter your password:
Error, incorrect password
Enter your password:
Error, incorrect password
Enter your password:
Login accepted, Dev. Number of attempts: 4

An empty password counts as a wrong attempt like any other:

Input:

Kim

abc123

Output:

Enter your username:
Enter your password:
Error, incorrect password
Enter your password:
Login accepted, Kim. Number of attempts: 2

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(...).

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, and all of it by the same amount. Never mix tabs and spaces in one file.
  • Any code that should run once the loop has finished is not indented, so the acceptance message is printed once rather than every time round the loop.
  • There is a password question and an 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.
  • The attempt counter is created before the loop, starts at 1, and is increased inside the loop.
  • The counter is wrapped in str() before it is joined onto text with a +.
  • Every space in the output comes from inside a string, so check the spaces around the username and the number.