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

"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...
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" } ...
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...
Modify the Assignment program from Module 1 to read a user's first and last name read...
Modify the Assignment program from Module 1 to read a user's first and last name read three integer scores, calculate the total and average determine the letter grade based on the following criteria - Average 90-100 grade is A, 80-89.99 grade is B, 70-79.99 grade is C, all others F (use a nested if) Output formatted results consisting of the full name, the three scores, the total, average (to 2 decimal places), and the letter grade go to step 1...
Step 1: The first thing you should do is modify the case conversion program that Neil...
Step 1: The first thing you should do is modify the case conversion program that Neil did in class. Instead of subtracting 32 from all numbers you want to add a constant number which we will call the key. Assume that all input will be lowercase. So it'll look like this, k = 2; letter = 'a'; newletter = k+letter; Above is pseudocode and ABOVE NOT ASSEMBLY CODE DO NOT COPY. Use bl puts the same way Neil did in...
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).
Modify the code below to implement the program that will sum up 1000 numbers using 5...
Modify the code below to implement the program that will sum up 1000 numbers using 5 threads. 1st thread will sum up numbers from 1-200 2nd thread will sum up numbers from 201 - 400 ... 5th thread will sum up numbers from 801 - 1000 Make main thread wait for other threads to finish execution and sum up all the results. Display the total to the user. #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define N_OF_THREADS 4 void * print(void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT