Please have it written in Python. Write a program with a main and a sub function
ID: 3806519 • Letter: P
Question
Please have it written in Python.
Write a program with a main and a sub function called check Password that checks whether a string is a valid password. The main function should get the user input as a string. Define the function as def check Password (password). This function returns whether the password is valid or invalid. Use string methods. Password rules: The password must are have at least eight characters. are contain at least two digits. are must contain at least one uppercase letter are must contain at least one lowercase letter are must contain at least one of [!,Explanation / Answer
def checkPassword(pw): chars = dig = up = lo = spl = 0 for c in pw: if c in ["!","@","#","$","%","^","&","*","(",")"] : spl=spl+1 for c in pw: chars=chars+1 for c in pw: if c.isdigit(): dig=dig+1 for c in pw: if c.isupper(): up=up+1 for c in pw: if c.islower(): lo=lo+1 if chars >= 8 and dig>=2 and up>=1 and lo>=1 and spl>=1: print("The Password you entered is valid ") else: print("The Password you entered is invalid ")