Answer:
def enterNewPassword():
while True:
password = input("Enter password: ")
has_digit = False
for i in password:
if i.isdigit():
has_digit = True
break
if not has_digit or (len(password) < 8 or len(password) > 15):
if len(password) < 8 or len(password) > 15:
print("The password length must be between 8 and 15!")
if not has_digit:
print("The password must include at least one digit!")
else:
return password
print(enterNewPassword())
Explanation:
*The code is in Python.
Create a function named enterNewPassword that takes no parameter
Create an indefinite while loop. Inside the loop, ask the user to enter the password. Initialize the has_digit as False, this will be used to check if password contains a digit or not. Create a for loop, that that iterates through the password, if one character is digit, set the has_digit as True and stop the loop (Use isdigit() to check if the character is digit or not).
After the for loop, check if has_digit is false or the length of the password is not between 8 and 15. If the length of the password is not between 8 and 15, print the error. If has_digit is false, again print the error.
Otherwise, password met the requirements and return the password
Call the enterNewPassword() function and print the result