Question

Write a Python program to create userids: You work for a small company that keeps the...

Write a Python program to create userids:

You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000

Your job is to create a program assign usernames for a login system. First: write a function get_parts(string) that will that will receive as its arguments a string with the client data , for example “Lin,Nenya,00358”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and end of the parts. You’ll need to use split(), lstrip() and rstrip() You can test your function by with a main() that is just the function call with the argument typed in. Second: write a function make_user(param) that will receive as its arguments three strings - the first name, last name, and client number and return the username. The user name should be created as • The first two characters of the first name, in lower case • The first two characters of the last name, in lower case • The last three characters of the user number For the example, the username for user Nenya Lin will be neli348 You’ll need to use slices, lower() and concatenation. You can test your function by with a main() that is just the function call with the arguments typed in. Finally: After your functions are working, write a main program to open the file (provided in the Assignments section on Blackboard), create usernames for the clients and print out client names and user names in a neat report format. For example

Client Username =======================

Sally Jones sajo345

Nenya Lin neli348

A Fule afu000

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

''' method to convert a line of data to individual parts'''
def get_parts(string):
    #splitting fields by comma
    fields=string.split(',')
    #taking value at index 0 as last name, stripping trailing and leading spaces
    last=fields[0].lstrip(' ').rstrip(' ')
    # taking value at index 1 as first name
    first=fields[1].lstrip(' ').rstrip(' ')
    # taking value at index 2 as user code
    usercode=fields[2].lstrip(' ').rstrip(' ')
    #returning all three values
    return first,last,usercode

''' method to create user id from first, last names and usercode'''
def make_user(first, last, usercode):
    #combining first two characters from first name, first two characters from last name
    #and last three characters from usercode, and returning it
    return first.lower()[:2]+last.lower()[:2]+usercode[-3:]

def main():
    #opening 'clients.txt' file, make sure file exists in same directory and is valid
    file=open('clients.txt')
    #printing heading
    print('{:15s} {:10s}'.format('Client','Username'))
    #printing a line of '====' characters
    print(25*'=')
    #looping through each line in file
    for line in file:
        #removing trailing newline if exists
        line=line.strip()
        #splitting into individual parts
        first,last,usercode=get_parts(line)
        #finding userid
        userid=make_user(first,last,usercode)
        #displaying values
        print('{:15s} {:10s}'.format(first+' '+last,userid))
    #closing file once loop is over
    file.close()

#calling main()
main()

#OUTPUT

Add a comment
Know the answer?
Add Answer to:
Write a Python program to create userids: You work for a small company that keeps the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

  • I need to create a code based off of what the users first name and last...

    I need to create a code based off of what the users first name and last name are along with a random set of numbers no longer than 10 characters as the picture below demonstrate (Java language) Scenario: You have been appointed by the CS department to create a username generator to create CS email accounts automatically. The CS email will have the following format: [email protected]. Your username must have a limit of 10 characters. Your program, will provide three...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • Please create a program answering the following question in C PROGRAMMING. CorrectFormation Create a program and...

    Please create a program answering the following question in C PROGRAMMING. CorrectFormation Create a program and locally declare in main fname and Iname and completeName. Ask the user for their first and last name. Put the values into fname and Iname. You will create a function that is called as followed oinNames( fname, Iname, completeName ); You will pass the first name array, the last name array, and the array that will contain the complete name. The function named joinNames...

  • For each problem, you must: Write a Python program Test, debug, and execute the Python program...

    For each problem, you must: Write a Python program Test, debug, and execute the Python program Save your program in a .py file and submit your commented code to your Student Page. Note regarding comments: For every class, method or function you create, you must provide a brief description of the what the code does as well as the specific details of the interface (input and output) of the function or method. (25 pts.) Write a program that reads in...

  • Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

    Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings. Create a MATLAB script named namephone.m and place these lines of code at the beginning: name  = input('Enter your first and last name: ','s'); phone = input('Enter your area code and phone number: ','s'); Tasks Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep As you work...

  • Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the...

    Create a New Java Project called YourLastNameUpperCase. Write a program that asks the user for the names of two files. The first file should be opened for reading and the second file should be opened for writing. The program should read the contents of the first file, change all characters to uppercase, and store the results in the second file. The second file will be a copy of the first file, except that all the characters will be uppercase. Use...

  • Write a complete Python program with prompts for the user for the main text file (checks...

    Write a complete Python program with prompts for the user for the main text file (checks that it exists, and if not, output an error message and stop), for any possible flags (including none), and for any other input that this program may need from the user: split has an option of naming the smaller files head_tail list the first 10 lines (default) and the last 10 lines (default) in order of the given text file flag: -# output #...

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

  • Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need...

    Lab 3: Databased Admin Tool Python Objective: Develop an admin tool for username and password management. You will need to use the best data structure to store the data you read from UD.txt for efficient processing. You can accomplish these tasks with Dictionary or List. The data file (UD.txt) : FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave,Dcon,dcf987, BHYW4fw Dell,Grant,dgr803,Sb83d2d Mike,Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt Give the following options: A: Search by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT