Write a function called format_name that accepts a string in the format of first name followed by
Fantastic news! We've Found the answer you've been seeking!
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 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
Related Book For
Accounting Business Reporting for Decision Making
ISBN: 9780730302414
4th edition
Authors: Jacqueline Birt, Keryn Chalmers, Albie Brooks, Suzanne Byrne, Judy Oliver
Posted Date: