167k views
0 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 Jones, Maya

User DomiSchenk
by
6.0k points

1 Answer

2 votes

Answer:

Written in Python:

import re

name = input("Name: ")

print(re.sub("[ ]", ", ", name))

Step-by-step explanation:

This line imports the regular expression library

import re

This line prompts user for input

name = input("Name: ")

This line replace the space with comma and prints the output

print(re.sub("[ ]", ", ", name))

User Arton Dorneles
by
6.5k points