In: Computer Science
Please make the following changes to the following code:
#This program takes in the first and last name and creates a userID printing first letter of first name and first 7 characters of last name #by Abi Santo #9/20/20 def main(): print("This Program takes your first and last name and makes a User ID") f_name = str(input("Please enter your first name ")).lower() l_name = str(input("Enter your last name: ")).lower() userID = str(f_name[:1]+str(l_name[:7])) print(userID) main()
If a "True" value is received from checkFirstCharacter (see above), then main() will call checkRemainingChars(), passing the remainder of the password. checkRemainingChars() will check to see if the remainder of the string is alphabetic or numeric, and return a True or False value back to main().
If either checkFirstChar or checkRemainingChars returns a value of "False", main() will issue an appropriate error message (specific to which was in error), and prompt the user for a new password.
Once the entire password has been validated, main() will print a "Password accepted" message to the user.
def main(): #defining the main function
print("This Program takes your first and last name and makes a User ID")
f_name = str(input("Please enter your first name ")) #to input the first name
l_name = str(input("Enter your last name: ")) #to input the last name
userID=createUserName(f_name,l_name) #to create userId, call function createUserName()
print(userID) #print the value of userID
Check = False #defining a check value to check validation of password
while (Check != True): #while loop until the password is valid
password=createPassword() #calling createpassword function
Check=checkFirstCharacter(password) #calling checkFirstCharacter function
if (Check == False): #checking if the first character of password is a digit
print("First character of the password should be an alphabet")
continue #again enters the password
else: #checking if the first character of password is alphabet
Check=checkRemainingChars(password) #when first character is alpha, calling checkRemainingChars function
if(Check == False): #if any value of other characters of password is a digit
print("Please enter the remaining characters of the password as alphabets")
continue #again enters the password and repeats process, until password is validated
print ("Password accepted") #exits the loop, with a valid password
def createUserName(f_name,l_name): #defining function createUserName
userID = str(f_name[0]+str(l_name[:7])) #concatenate first alphabet of f_name with seven letters of l_name
return userID #returning the userID created
def createPassword(): #defining function createPassword
password=str(input("Enter your password: ")) #ask the user to enter the password
return password #return password to the main function
def checkFirstCharacter(password): #defining function checkFirstCharacter
return(password[0].isalpha()) #returning true if first character is alphabet, else false
def checkRemainingChars(password): #defining function checkRemainingChars
return(password[1:].isalpha())#returning true if other characters are alphabet, else false
main()
Comment in case of doubts