101k views
1 vote
Ex: If the input is: Pat Silly Doe the output is: Doe, P.S.

1 Answer

3 votes

Answer:

Full_name=input("Enter Full Name: ").split()

len1=len(Full_name)

if len1 == 3:

print(Full_name[2]+", "+Full_name[0][0]+"."+Full_name[1][0]+".")

if len1 == 2:

print(Full_name[1]+", "+Full_name[0][0]+".")

Step-by-step explanation:

We first get full names as input from the user. And then split into words, and finally, we store it in the list. Now we calculate the length of that list. The name in general 3 words long, And hence, we can assume here that maximum length is 3, and it can be 2 definitely. Now if the length is 3 we print the third word or last name in full, and the first letter of the middle name and first name. Also, if the maximum length is 2 then we print the middle name in full, and this is the last name in this case. Also, we print the first letter of the first name. And thus, we have our solution.

User Sarvesh Shetty
by
3.6k points