148k views
1 vote
Python

Function Name: lastF Parameters: string Returns: string Description: Write function *lastF that takes as input a string of the form 'FirstName LastName' and returns a *string of the form 'LastName, F.'. *(Only the initial should be output for the first name)
Sample Inputs/Outputs:
Example Call: lastF('John Locke')Expected Return: 'Locke, J.'

User Eva Lacy
by
4.0k points

1 Answer

2 votes

Answer:

#Program starts here

#Prompt User for Input "FirstName and LastName "

FirstName = input("Enter Your FirstName: ")

LastName = input("Enter Your LastName: ")

#Define Function

def lastF(FirstName, LastName):

FirstName = FirstName[0]+"."

print(LastName+", "+FirstName);

lastF(FirstName, LastName) #Call Function

#End of Program

Step-by-step explanation:

On line 3 and 4, the user is expected to enter his/her first name and last name respectively

On line 6, the function LastF with two arguments is defines

On line 7, the initial of FirstName is extracted

Line 8 prints the required output

Line 9 Calls the defined function.

User Esaevian
by
3.5k points