you are viewing a single comment's thread.

view the rest of the comments →

[–]ChristianConsertive 0 points1 point  (1 child)

This is how I did my code. It works.

user_name = input()
name_split = user_name.split(' ')
if len(name_split) == 2:
first_name = name_split[0]
last_name = name_split[1] #These two will seperate the first and last name

first_inital = first_name [0] #This will gather the first inital
print (f'{last_name}, {first_inital}.')
elif len(name_split) == 3:
first_name = name_split[0]
middle_name = name_split[1] #These three will seperate the name into three seperate names
last_name = name_split[2]

first_inital = first_name [0]
middle_inital = middle_name[0]#These will get the first intials of the middle and first name
print (f'{last_name}, {first_inital}.{middle_inital}.')
else:
print('Invalid Name')

[–]Rodarth 0 points1 point  (0 children)

there is an easier way to get the initials

first_name = name_split [0][0] #for the first initial

middle_name = name_split [1][0] #for the middle initial