Write a program password.py that asks a user for a valid password. The program should keep asking for a password, until the user enters the right password. Here are the requirements for a valid password: 1- Must be between 4 and 8 characters (inclusive) 2- The first character of the password must be in uppercase 3- The last character of the password must be a number

Respuesta :

Answer:

The program in Python is as follows:

password = input("Password: ")

while(True):

   if len(password) >=4 and len(password) <=8:

       if password[0].isupper():

           if password[-1].isdigit():

               break;

   password = input("Password: ")

print("Correct Password")

Explanation:

This gets input for the password

password = input("Password: ")

This loop is repeated while the password does not meet the 3 rules

while(True):

This checks for length

   if len(password) >=4 and len(password) <=8:

This checks if first character is upper case

       if password[0].isupper():

This checks if last character is a digit

           if password[-1].isdigit():

If the conditions are met, the loop is exited

               break;

This gets input for password, if any of the conditions fail

   password = input("Password: ")

This ends the program

print("Correct Password")

ACCESS MORE