Back

Password - Answers

Q1. Type the code in and get it working.
Q2.
The user must either enter in the correct password to proceed, or if they get it wrong three times, then they have to contact the Network Manager.
Q3. Yes, it's a good password because it is more than 8 characters, uses capital, small letters, numbers and symbols.
Q4. Initialisation occurs on line 3.
Q5. The program will run, but if you enter the correct password in the first few attempts, it will ask you to re-enter it.
Q6. == is used to compare values. = is used to assign one value to another.
Q7. Change line 1 to:

password = input("Please set the password")

Q8. See the Downloads section.

password1 = "fish"
password2 = "fingers"
print("Please set the password. you must enter it in twice.\n\n")

while password1 != password2:
    password1 = input("Please set the password >>> ")
    password2 = input("Please enter in your chosen password again >>> ")
    if password1 != password2:
        print("\nSorry. The two passwords you entered do not match. Please try again\n")

print("\nCongratulations. The new password has been accepted. Please enter your password to login >>> \n\n")


counter = 1
guess = input("Please enter password >>> ")
while (guess!=password1) and (counter<3):
     guess = input("Please enter password >>> ")
    counter = counter + 1

if guess == password1:
    print("Continue")
elif counter >= 3:
    print("Contact Network Manager")

input("Press <ENTER> to quit >>>>")

Q9. You could inform the user how many times they attempted to login. You could allow a change of password only if they can enter in the current password. You could limit the number of chances they can have to set a new password. You could set up some data validation to force the user to make the password more than 8 characters, or to ensure they use a mix of numbers, capital letters, small letters and symbols.
Q10. This program is a common task. Once written and tested, it could be put into a library and other programmers could use it. They wouldn't have to reinvent the wheel and write their own code.

Back