Question: Write some code that repeatedly asks the user to enter a password until they enter the correct one. ( The correct password is python 1

Write some code that repeatedly asks the user to enter a password until they enter the correct one. (The correct password is "python123".) Count the number of incorrect attempts and display it once the correct password is entered.
Your code should perform the following steps:
Use a while loop to prompt the user to enter a password with the following prompt:
Enter the password:
If the user enters the wrong password, increase the count of invalid attempts by 1 and prompt the user again.
The loop should stop only when the user enters the correct password, which is "python123".
Once the correct password is entered, display the total number of invalid attempts, using the following format:
Number of invalid attempts: 3
In the following sample run, the user enters the password incorrectly two times and then correctly the third time:
Enter the password: wrongpass
Enter the password: anotherwrongpass
Enter the password: python123
Number of invalid attempts: 2
In the following sample run, the user enters the correct password the first time:
Enter the password: python123
Number of invalid attempts: 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!