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:...
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...
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: """...
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....
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
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
Please can you draw a flow chart for the following code : Program code for Payroll,java:...
Please can you draw a flow chart for the following code : Program code for Payroll,java: public class Payroll { public Payroll(String name,int ID,double payRate) { this.name=name; this.ID=ID; this.payRate=payRate; } private String name; private double payRate,hrWorked; private int ID; public Payroll() { name="John Doe"; ID=9999; payRate=15.0; hrWorked=40; } public String getName() { return name; } public int getID() { return ID; } public void setPayRate(int payRate) { this.payRate=payRate; } public void setHrWorked(double hrWorked) { this.hrWorked=hrWorked; } public double getPayRate() {...
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...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ *...
Please take this c++ code and make it into java code. /* RecursionPuzzleSolver * ------------ * This program takes a puzzle board and returns true if the * board is solvable and false otherwise * * Example: board 3 6 4 1 3 4 2 5 3 0 * The goal is to reach the 0. You can move the number of spaces of your * current position in either the positive / negative direction * Solution for this game...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT