Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Intro to Python: Functions Consider a password valid if it contain only alphabet

ID: 3820250 • Letter: I

Question

Intro to Python: Functions

Consider a password valid if it contain only alphabets and numbers. Additionally it must contain at least one uppercase letter and at least one number and must be 7 characters or longer. Write a function, called isValid, which takes a string as a parameter and returns the Boolean value True if it is a valid password and the Boolean value False if it is not. Depending on what the function returns for an inputted password output if it is valid or not.

Note: you will get the return value from the function isValid and depending on the returned value you will print one line or the other.

Sample output1:

Enter the password: Abc123A

The passwordisvalid

Explanation / Answer

import re

p = input("Enter the Password: ")

if re.match(r'[A-Za-z0-9]{7,}',p):
print("The password is valid")
else:
print("The password is invalid")

Sample Output:

Enter the Password: Abc123A
The password is valid

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote