Question

In: Computer Science

Modify the username.py program (see the lecture slide) to generate usernames using the user’s first initial,...

Modify the username.py program (see the lecture slide) to generate usernames using the user’s first initial, followed by up to 3 first letters of the user’s last name, and a number of total characters in the last name. User input can be up- or low-case. But the generated usernames contains only low-case characters and a number.

For example, if the person’s name is “Albert Einstein” à the username shall be ”aein8”

Tip: use len() function and string’s lower() method

To create the program(10 points): :

1. Create a module named h02_username2.py from the directory hw

2. Record your name, class number, and date of creation using python comment statement.

3. Write the code to implement the required tasks.

When you have completed the program, run the program and capture and paste the output below:

Solutions

Expert Solution

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

#code

def main():

    # get user's first and last names, converting each to lower case

    first = input("Please enter your first name (all lowercase): ").lower()

    last = input("Please enter your last name (all lowercase): ").lower()

    #assuming first name is not empty and last name contains at least 3 characters

    #taking first character of first name, concatenating with first 3 characters of

    #last name and total length of last name

    uname=first[:1]+last[:3]+str(len(last))

    # displaying the generated username

    print("Your username is:", uname)

main()

#output

Please enter your first name (all lowercase): Albert

Please enter your last name (all lowercase): Einstein

Your username is: aein8

#another output

Please enter your first name (all lowercase): Oliver

Please enter your last name (all lowercase): Queen

Your username is: oque5


Related Solutions

A.Write a program that prompts for and reads the user’s first and last name (separately).Then print...
A.Write a program that prompts for and reads the user’s first and last name (separately).Then print the initials with the capital letters. (Note that we do not expect that inputs from users are case-sensitive. For example, if the user’s input of the first name is robert and of the last name is SMITH, you should print R.S.) B.Write a program that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashed in the output. Do not...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when...
"4. (Modify) Modify Program 7.14 so that the user inputs the initial set of numbers when the program runs. Have the program request the number of initial numbers to be entered." //C++ Program 7.14 as follows #include #include #include #include using namespace std; int main() { const int NUMELS = 4; int n[] = {136, 122, 109, 146}; int i; vector partnums(n, n + NUMELS); cout << "\nThe vector initially has the size of " << int(partnums.size()) << ",\n and...
Create a C++ login program using file for 2 user. Usernames must be in one file...
Create a C++ login program using file for 2 user. Usernames must be in one file and password in the other file. Ask user for their usernames and password if it matches, they logged in successfully. If it doesn’t match,they have 3 trials ,then they have to sign in and create a username and password. After creating a username and password, they have to go to the login page again. Must work for visual studio code
In java Modify your finished guessNumber.java program to include a random number generator to generate the...
In java Modify your finished guessNumber.java program to include a random number generator to generate the guessed number (from 1 to 10). use the Random class to generate a random number between a range of integers. In your program include an if … then statement to check if the number you entered is bigger or smaller than the guessed number, and display a message. Also included is a counter to keep track on how many times the user has guessed,...
Write a program that accepts user’s name, password and address and display them back using the...
Write a program that accepts user’s name, password and address and display them back using the format “Hi, I am user’s name. I live at user’s address.”. Restrictions: ▪ Use only three variables. ▪ Make sure you support spaces.
PYTHON Modify the program in section Ask the user for a first name and a last...
PYTHON Modify the program in section Ask the user for a first name and a last name of several people.  Use a loop to ask for user input of each person’s first and last names  Each time through the loop, use a dictionary to store the first and last names of that person  Add that dictionary to a list to create a master list of the names  Example dictionary: aDict = { "fname":"Douglas", "name":"Lee" } ...
Write a program that will search through an array and check to see if the first...
Write a program that will search through an array and check to see if the first number in the array occurs more than once. If the first number occurs more than once, return true. Otherwise, return false. If the array is empty, return false? You will need to use a variable, loop, and if statement.
Modify Java program to accept a telephone number with any numberof the letters, using the...
Modify Java program to accept a telephone number with any number of the letters, using the if else loop. The output should display a hyphen after the first 3 digits and subsequently a hyphen (-) after every four digits. Also, modify the program to process as many telephone numbers as the user wants.
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Using P18f4580 controller - Write a program in C using Timer0 to generate a square wave...
Using P18f4580 controller - Write a program in C using Timer0 to generate a square wave with a frequency of 1kHz on PORTBRB5? (Assume XTAL = 20 MHz).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT