128k views
3 votes
Write a program that reads a person's first and last names separated by a space, assuming the first and last names are both single words. Then the program outputs last name, comma, first name. End with newline. Example output if the input is: Maya Jones

User Kamini
by
5.0k points

1 Answer

3 votes

Final answer:

The program reads a person's first and last names, splits them using the split() method, and outputs the last name followed by the first name, separated by a comma.

Step-by-step explanation:

A program that reads a person's first and last names and then outputs the last name followed by a comma and the first name can be implemented in various programming languages. Here is an example using Python:

first_name, last_name = input('Enter first and last name: ').split()
print(f'{last_name}, {first_name}')

When a user inputs the names 'Maya Jones', the program will output:

Jones, Maya

The program splits the input string into two parts using the split() method, assigning the first part as first_name and the second part as last_name. It then prints the last name, a comma, and the first name in the required format.

User Hishadow
by
4.7k points