Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a program that asks for a password, again and again, until the user types python123. Then it shows Access granted. Show Wrong password after each wrong try, and count the tries.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. The number of tries is not known, so use a loop that asks until the answer is right. The user types an answer in the Input box on each line.
Notice the start: password = "" is not the right password, so the loop begins. Inside the body, the message Wrong password is shown only when the answer is wrong, so the right password does not show it.
Check. The answers abc, python, python123 give two lines of Wrong password and then Access granted after 3 tries.
Answer: The program above.
Log in to join the discussion.
Loading…