In: Computer Science
Please add a statement that requires a number in the password to the following code:
#Lab on functions
#By Abi Santo
#10/25/20
def get_first_and_last_names():
first = input("Enter your first name: ")
last = input("Enter your last name: ")
return (first.lower(), last.lower())
def create_username(name_list):
uname = name_list[0] +"." + name_list[1]
return uname
def create_password():
passwd = input("Create a new password: ")
#make sure the password has atleast 8 characters
while len(passwd)<8:
print("Fool of a Took! That password is feeble!")
passwd = input("Create a new password: ")
while passwd.lower() == passwd:
print("The password must contain at least one uppercase
character")
passwd = input("Create a new password: ")
print("The force is strong in this one...")
print("Your password has been accepted.")
return passwd
def main():
#Get user's first and last name
first_last_name_list = get_first_and_last_names()
#create a username using the first and last name
username = create_username(first_last_name_list)
#ask the user to create a new password
password = create_password()
print("Account configured. Your new email address is: ",
username + "@marist.edu")
main()
code analysis:
After giving first name and last name.....
If we give "pavan" as passwd. It did not accept since it has less than 8 characters.
Then we give...."pavankumar" as passwd. Since it has atleast 8 characters..it moved on to check whether it has an uppercase character. since it does not..program asked for passwd again.
At this stage I gave "Pavan". The program accepted.though there are less than 8 characters. It's actually worng.
Code:
def get_first_and_last_names():
first = input("Enter your first name: ")
last = input("Enter your last name: ")
return (first.lower(), last.lower())
def create_username(name_list):
uname = name_list[0] +"." + name_list[1]
return uname
def create_password():
passwd = input("Create a new password: ")
while(True):
flag_digit = False
length = len(passwd)
upper_check = (passwd.lower() == passwd)
for symbol in passwd:
if symbol.isdigit():
flag_digit = True
#make sure the password has atleast 8 characters. Otherwise read passwd again from user and check from initial condition
if length < 8:
print("Fool of a Took! That password is feeble!")
passwd = input("Create a new password: ")
continue
#If the passwd has 8 characters. Make sure the passwd also has an upper case character: Otherwise read passwd again from user and check from initial condition
elif upper_check == True:
print("The password must contain at least one uppercase character")
passwd = input("Create a new password: ")
continue
#If the passwd has 8 characters and an uppercase character make sure it also has digit. Otherwise read passwd again from user and check from initial condition
elif flag_digit == False:
print("Password should contain atleast one digit")
passwd = input("Create a new password: ")
continue
#If it satisifies all the conditions...BREAK
else:
print("The force is strong in this one...")
break
print("Your password has been accepted.")
return passwd
def main():
#Get user's first and last name
first_last_name_list = get_first_and_last_names()
#create a username using the first and last name
username = create_username(first_last_name_list)
#ask the user to create a new password
password = create_password()
print("Account configured. Your new email address is: ", username + "@marist.edu")
main()
PLEASE....Rate....If you like the answer......