Question

In: Computer Science

Please make the following changes to the following code: #This program takes in the first and...

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()
  1. Call the function createUserName(). This function will prompt the user for first and last names, create the userid from the first initial plus the last name, and return the userid to the main() function
  2. main() will print out the userid returned from the createUserName().
  3. main will then call the function createPassword(). This function will prompt the user for a password. It will return the password to main()
  4. The main() function will then call checkFirstCharacter(), passing the first character of the password. CheckFirstCharacter() will check to see if the first character is alphabetic, and return either a True or False value back to main().
  5. 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().

  6. 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.

  7. Once the entire password has been validated, main() will print a "Password accepted" message to the user.


please use python

Solutions

Expert Solution

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


Related Solutions

Please provide Python code that does the following: 3) Write a program that takes a string...
Please provide Python code that does the following: 3) Write a program that takes a string as input, checks to see if it is comprised entirely of letters, and if all those letters are lower case. The output should be one of three possible messages: Your string is comprised entirely of lower case letters. Your string is comprised entirely of letters but some or all are upper case. Your string is not comprised entirely of letters. Your program may NOT:...
I need to make changes to code following the steps below. The code that needs to...
I need to make changes to code following the steps below. The code that needs to be modified is below the steps. Thank you. 1. Refactor Base Weapon class: a.            Remove the Weapon abstract class and create a new Interface class named WeaponInterface. b.            Add a public method fireWeapon() that returns void and takes no arguments. c.             Add a public method fireWeapon() that returns void and takes a power argument as an integer type. d.            Add a public method activate()...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
First make the changes in P82.cpp and call the new program ex82.cpp. Compile and run the...
First make the changes in P82.cpp and call the new program ex82.cpp. Compile and run the program and make sure it produces the correct results. Here is what you need to do for the exercise:     Overload the % operator such that every time you use it, it takes two objects of type AltMoney as its arguments and returns:             a) 5% of the difference between the income and expenditure, if income is larger than the expenditure             b) -2%...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please...
1. Please program the following in Python 3 code. 2. Please share your code. 3. Please show all outputs. Instructions: Run Python code  List as Stack  and verify the following calculations; submit screen shots in a single file. Postfix Expression                Result 4 5 7 2 + - * = -16 3 4 + 2  * 7 / = 2 5 7 + 6 2 -  * = 48 4 2 3 5 1 - + * + = 18   List as Stack Code: """...
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
C++ code please: Write a program that first gets a list of integers from input. The...
C++ code please: Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, which indicates how much to multiply the array by. Finally, print out the entire array with each element multiplied by the last input. Assume that the list will always contain less than 20 integers. Ex: If the input is 4 4 8 -4 12...
Using the code below from “LStack.h” file, write the code for a main program that takes...
Using the code below from “LStack.h” file, write the code for a main program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions { 25 + ( 3 – 6 ) * 8 } and 7 + 8 * 2 contains matching grouping symbols. However, the expression 5 + { ( 13 + 7 ) / 8 - 2 * 9 does not contain matching grouping symbols....
create a VHDL program for the Truth Table below. Please make sure to create your code...
create a VHDL program for the Truth Table below. Please make sure to create your code for the simplified circuit. A B C Z 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 0
Make the following matlab function. D=inverses(A) It takes the input of an nxn matrixA. First, the...
Make the following matlab function. D=inverses(A) It takes the input of an nxn matrixA. First, the function has to determine whether A is invertible (you may want to use the function rank to do that). If A is not invertible, the function has to return an empty matrix D=[ ]; and terminates with a message “Matrix A is not invertible”. If A is invertible, then the function reduces the matrix [A eye(n)] into the reduced echelon form and returns the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT