Kristina D.

asked • 10/14/20

Creating a Name-Sorting Program in Python

Hi I really need help in my programming class with this assignment!!!


Write a function named split_name which takes one parameter called name. If the name parameter value is a name in the form Lastname, FirstName (e.g., ”Grounds, Nic”) then the function should return a list of two elements where FirstName is the first element and LastName is the second element. If the name parameter value is a name in the form FirstName LastName (e.g., ”Nic Grounds”) then the function should return a list of two elements where FirstName is the first element and LastName is the second element. Repeatedly prompt the user for a name (which the user may give in LastName, FirstName form, or FirstName LastName form). If the user’s response is an empty string (i.e., they simply press Return) cease looping. If the user’s response is not the empty string, call the split_name function you wrote and append the returned value to a list (initially empty). Using the sorted function (which can take a single parameter, a list) and returns a copy of the list in sorted order) sort the list of names once the loop has finished. Print the sorted list of names, one name per line in LastName, FirstName form.

Kristina D.

Sample potential execution of a program meeting the requirements: Welcome to my name-sorter program. Enter names in either "lastname, firstname" or "firstname lastname" form. When you are done entering names, enter nothing and press Return. Jim Halpert Pam Beasley Martinez, Oscar Michael Scott Dwight Schrute Martin, Angela Malone, Kevin Creed Bratton The sorted list of names is: Martin, Angela Bratton, Creed Schrute, Dwight Halpert, Jim Malone, Kevin Scott, Michael Martinez, Oscar Beasley, Pam
Report

10/14/20

1 Expert Answer

By:

Patrick B. answered • 10/14/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Kristina D.

What would I need to add to make sure the names are printed in alphabetical order?
Report

10/15/20

Patrick B.

the sort method does that... To make double sure, I would use all uppercase or all lower case
Report

10/19/20

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.