47.4k views
7 votes
2.12 lab: name format many documents use a specific format for a person's name. write a program whose input is: firstname middlename lastname and whose output is: lastname, firstinitial.middleinitial.

1 Answer

2 votes

Answer:

if __name__ == '__main__':

user_input = input() # read name

name = user_input.split() # split name into separate words

if len(name) == 3: # if number of words in name is 3

print(name[2] + ", " + name[0][0] + "." + name[1][0] + ".")

elif len(name) == 2: # if number of words in name is 2

print(name[1] + ", " + name[0][0] + ".")

Step-by-step explanation:

The code is written in "Python".

User Kerat
by
4.5k points