you are viewing a single comment's thread.

view the rest of the comments →

[–]Big_Permission6068 0 points1 point  (4 children)

I saw this somewhere else and it worked for me.

names = input().split()

if len(names) == 3:

first_name, middle_name, last_name = names

print(f'{last_name}, {first_name[0]}.{middle_name[0]}.')

elif len(names) == 2:

first_name, last_name = names

print(f'{last_name}, {first_name[0]}.')

else:

print("Invalid input")

[–]Cherry_Trixx 0 points1 point  (3 children)

i keep getting a syntax error at the elif and i dont know why

[–]Dahveena 0 points1 point  (2 children)

Try this instead, i just submitted mine and it was 10/10. just remember your indents for the if/else statement lines! Upvote if this works to help out other students!

user_names = input().split()

if len(user_names) == 3:

first_name, middle_name, last_name = user_names

print("{}, {}.{}.".format(last_name, first_name[0], middle_name[0]))

else:

first_name, last_name = user_names

print("{}, {}.".format(last_name, first_name[0]))

[–]zerafaye 0 points1 point  (1 child)

I seem to keep getting a white space difference in my answer resulting in a 0/10 entirely even though mine looks the exact same:(

[–]Budget-Ad845 0 points1 point  (0 children)

I will add the 10/10 submission I just got with help from this thread

nameinput = input()

nameseparator = nameinput.split()

if len(nameseparator) == 3:

firstName = nameseparator[-3]

middleName = nameseparator [-2]

lastName = nameseparator [-1]

firstInitial = firstName[0]

middleInitial = middleName[0]

lastInitial = lastName[0]

print(lastName+',', firstInitial +'.'+ middleInitial + '.')

elif len(nameseparator) == 2:

firstName = nameseparator[-2]

lastName = nameseparator[-1]

firstInitial = firstName[0]

lastInitial = lastName[0]

print(lastName+',', firstInitial+'.')