Question

Provide Python code that does the following: 4) Write a program that asks the user to...

Provide Python code that does the following:

4) Write a program that asks the user to enter a 9 character password. Test to see if it is a valid password. The validity test is

a) they enter exactly 9 characters AND

b) that every 3rd character, starting with the 1st character is the letter z.

If it is valid print out the message “valid password” otherwise print the message “invalid password”.

Sample output.

Please enter a password: zaazbbz12

valid password

Please enter a password: Aaazbbz12

invalid password

Please enter a password: zaaz

invalid password

Homework Answers

Answer #1
password = input('Please enter a password: ')   # read password

# check if length of password is exactly 9
if len(password) != 9:
   print('invalid password')
   
else:
   # check if every 3rd character is z in the password
   is_valid = True
   for i in range(0, 9, 3):
      if password[i] != 'z':
         is_valid = False
         break
         
   if is_valid:
      print('valid password')
   else:
      print('invalid password')

FOR HELP PLEASE COMMENT.
THANK YOU

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a program that asks the User to enter a letter, then asks the user to...
write a program that asks the User to enter a letter, then asks the user to enter a sentence. the program will then print out how many time that letter occurred in the sentence. in C Language
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
Write a program that asks the user to input an integer between 25 and 50, inclusive....
Write a program that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2 relational expressions. You...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If...
Write an assembly program which asks user to enter a character from ‘A’ to ‘Z’. If the user enters any other character, the program asks user to enter the character again. In this way the program inputs 300 characters and stores it in memory location from address $1000 to $112B. Hint: Use CPU register Y as counter
Write a program that asks the user to enter three different integers; if the entered three...
Write a program that asks the user to enter three different integers; if the entered three integers contain two or more that are the same, print message "wrong input"; otherwise the program prints the largest number in the three. Implement your code using decision structures (namely, if and/or if-else). In the execution of your code, try the following test cases. Test case 1: input (3, 4, 5) Test case 2: input (3, 3, 5) Test case 3: input (3, 5,...
Having a secure password is a very important practice, when much of our information is stored...
Having a secure password is a very important practice, when much of our information is stored online. Write a program that validates a new password, following these rules:5 pts The password must be at least 8 characters long The password must have at least one uppercase and one lowercase letter The password must have at least one digit The program must also ask for a user to enter it and then confirm it: Enter your password: Re-enter your password: If...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints...
Question1: Write a Python Program that asks for the grades of 5 quizzes and then prints the highest grade. [6 Marks] Question2: Write a Python Program that does the following tasks. [8 Marks] Create an empty list Ask the user for 5 positive numbers and append them to the list Find and print the sum of all the numbers in the list Delete the last element from the list and then print the list Question3: Consider you have the following...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Design a program that asks user to enter any three numbers. The program should display the...
Design a program that asks user to enter any three numbers. The program should display the three numbers in ascending order. using python code please