Password¶
Save all functions into the same file named password.py.
Write the function
has_upppercase()that takes a string, and returnsTrueif it contains any uppercase letter andFalseotherwise.See the following examples:
>>> has_uppercase("Mypassword") True >>> has_uppercase("new#@*password657") False >>> has_uppercase("hi#@*U981") True >>> has_uppercase("05687xsd") False
Note
More tests are provided in the
password1.txtfile.Write the function
check_password()that takes two strings with a new and a previous password respectively. The function checks if the new password meets the system requirements. Specifically, the function must return an integer according to the following conditions referring to the new password:If it is equal to the previous password, return 1.
If there are not at least 8 characters, return 2.
If it does not contain at least one uppercase letter, return 3.
In any other case, return 0.
These conditions must be checked in the order indicated: or example if a new password does not have at least 8 characters and does not contain any uppercase letter, the function will return 2 (not 3). This function must call the previous one.
See the following examples:
>>> check_password("Mypassword", "Mypassword") 1 >>> check_password("new**3", "Mypassword") 2 >>> check_password("newpassword", "Mypassword") 3 >>> check_password("newpassWord", "Mypassword") 0
Note
More tests are provided in the
password2.txtfile.
Solutions
A solution of these functions is provided in the
password.py file.