Question: Write a function called format_name that accepts a string in the format of first name followed by last name as a parameter, and then returns

Write a function called format_name that accepts a string in the format of first name followed by last name as a parameter, and then returns a string in reverse order (i.e., last name, first name). You may assume that only a first and last name will be given.

For example, format_name("Jared Smith") should return "Smith, Jared"

Hint: The following String Methods will be useful:

# Returns the lowest index in the string where substring is # found. Returns -1 if substring is not found my_string = “eggplant” index = my_string.find(“plant”)      # returns 3 
# Returns all the characters after the specific index my_string = "hello world!" print my_string[1:] # returns "ello world!" print my_string[6:] # returns "world!" 
# Returns all the characters before the specific index my_string = "hello world!" print my_string[:6] # returns "hello" print my_string[:1] # returns "h"

Your program should include:

  • A main method that uses user input to prompt and read a string that contains a person's first name and last name
  • A call to format_name and a print statement that prints the output returned by format_name
  • A call to the main function

Step by Step Solution

3.54 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Implement in python formatnamepy def formatnamemystring s... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!