You now know enough to implement one of the programs we mentioned in Section 7.1: Change a name in the form "Fulano, Juan" to "Juan Fulano". We’ll use a function to do the heavy lifting.
Checkpoint7.9.1.
Put the steps in the pseudo-code for the function the right order:
Find position of comma in string
---
if position is >= 0:
---
take slice before the comma and put it in last_name
take slice after the comma and put it in first_name
---
strip leading and trailing blanks from first_name and last_name
set new_name to first_name + space + last_name
---
else:
---
set new_name to name (no comma found)
---
print the new_name
Checkpoint7.9.2.
Write the code in Python.
Use the find method to find the index where a comma occurs in the name. If there is no comma, the find method returns -1.
Use slices to extract the last name (everything from the beginning up to the comma) and first name (everything after the comma). Remember that the slice goes up to, but not including, the position specified by the number to the right of the :.
Use the strip method to strip leading and trailing spaces from a string.
Test your program with names like Fulano, Juan; van Gogh, Vincent; Marie Toulemonde; and Prince.