In: Computer Science
In Python, write a function called user_name that takes two arguments, first_name and last_name and creates a “user name” consisting of the first three letters of the first name concatenated with the first three letters of the last name. You can assume ach name is at least three letters long.
Return the new user name.
your results should yield something like these test cases.
>>> print(user_name("bob", "taft"))
bobtaf
>>>
>>> print(user_name("Ralph", "Waldo"))
RalWal
>>>
Program :
Program screenshots are given for the understanding of the indentation and comments are also included in the program.
main.py
#function username which takes two arguments
#first_name and the last_name
def user_name(first_name, last_name) :
'''
new name
*concatenating the string using + operator
*[:3] -> specifies taking only 3 letters
*from the starting of the string
'''
new_name = first_name[:3]+last_name[:3]
#then return this new name
return new_name
#now calling this function with the test cases.
print(user_name("bob","taft"))
print(user_name("Ralph","Waldo"))
#making program to work with this
#taking input for the first name and last name
first_name = input("Enter first name : ")
last_name = input("Enter the last name : ")
#print the new name by calling the function user_name(-,-)
print("New username : ",user_name(first_name,last_name))
Output screenshots :
Program screenshots :