Write a function called format_name that accepts a string in the format of first name followed by...

80.2K

Verified Solution

Question

Programming

Write a function calledformat_name that accepts a string in the format offirst name followed by last name as a parameter, and thenreturns a string in reverse order(i.e., last name, first name). You may assume that only a first andlast 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 foundmy_string = “eggplant”index = my_string.find(“plant”)   # returns 3# Returns all the characters after the specific indexmy_string = \"hello world!\"print my_string[1:] # returns \"ello world!\"print my_string[6:] # returns \"world!\"# Returns all the characters before the specific indexmy_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 stringthat contains a person's first name and last name
  • A call to format_name and a print statement that prints theoutput returned by format_name
  • A call to the main function

PLEASE HELP PYTHON COMPUTER SCIENCE

Answer & Explanation Solved by verified expert
3.8 Ratings (481 Votes)
The following code has been written in Python 3 For testingpurpose we have considered the same example name and shown theoutput after executing the codeSource code Following function    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students