In: Computer Science
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:
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