Apr-04-2020, 11:59 PM
I am learning python and trying to solve different problems i came across this program which is name mashup which is in Get Programming:Learn to code with Python.
problem statement: Write a program that automatically combines two names given by the user. That’s an open-ended problem statement, so let’s add a few more details and restrictions: -Tell the user to give you two names in the format FIRST LAST. Show the user two possible new -names in the format FIRST LAST. -The new first name is a combination of the first names given by the user, and the new last -name is a combination of the last names given by the user. For example, if the user gives you -Alice Cat and Bob Dog, a possible mashup is Bolice Dot.
I'd like to know is there any way to improve this program like using functions to make this program better.
problem statement: Write a program that automatically combines two names given by the user. That’s an open-ended problem statement, so let’s add a few more details and restrictions: -Tell the user to give you two names in the format FIRST LAST. Show the user two possible new -names in the format FIRST LAST. -The new first name is a combination of the first names given by the user, and the new last -name is a combination of the last names given by the user. For example, if the user gives you -Alice Cat and Bob Dog, a possible mashup is Bolice Dot.
I'd like to know is there any way to improve this program like using functions to make this program better.
print('Welcome to the Name Mashup Game') name1 = input('Enter one full name(FIRST LAST): ') name2 = input('Enter second full name(FIRST LAST): ') space = name1.find(" ") name1_first = name1[0:space] name1_last = name1[space+1:len(name1)] space = name2.find(" ") name2_first = name2[0:space] name2_last = name2[space+1:len(name2)] # find combinations name1_first_1sthalf = name1_first[0:int(len(name1_first)/2)] name1_first_2ndhalf = name1_first[int(len(name1_first)/2):len(name1_first)] name1_last_1sthalf = name1_last[0:int(len(name1_last)/2)] name1_last_2ndhalf = name1_last[int(len(name1_last)/2):len(name1_last)] name2_first_1sthalf = name2_first[0:int(len(name2_first)/2)] name2_first_2ndhalf = name2_first[int(len(name2_first)/2):len(name2_first)] name2_last_1sthalf = name2_last[0:int(len(name2_last)/2)] name2_last_2ndhalf = name2_last[int(len(name2_last)/2):len(name2_last)] new_name1_first = name1_first_1sthalf + name2_first_2ndhalf new_name1_last = name1_last_1sthalf + name2_last_2ndhalf new_name2_first = name2_first_1sthalf + name1_first_2ndhalf new_name2_last = name2_last_1sthalf + name1_last_2ndhalf # print results print(new_name1_first, new_name1_last) print(new_name2_first, new_name2_last)