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. Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is______________.

Respuesta :

Answer:

The solution code is written in Python:

  1. name = input("Enter your name: ")
  2. name_components = name.split(" ")
  3. first_name = name_components[0]
  4. middle_name = name_components[1]
  5. last_name = name_components[2]
  6. print(last_name + ", " + first_name[0] + "." + middle_name[0])

Explanation:

Firstly, prompt user to enter name (Line 1).

Next, use the string split() method and use space " " as separator to split the input string into individual component, first name, middle name, last name and assign to variable first_name, middle_name and last_name (Line 5-7).

Display the output as required by the question.