I am currently working on a problem where I am trying to to turn a full name “First Middle Last” into their Last Name, X.Y
. X
representing their first initial and Y
representing their middle initial.
full_name = input()
full_name2 = full_name.split(' ')
first_name = full_name2[0]
middle_name = full_name2[1]
last_name = full_name2[2]
first_name2 = list(first_name)
middle_name2 = list(middle_name)
first_inital = first_name2[0]
middle_inital = middle_name2[0]
print(last_name + ', ' + first_inital, '.' + middle_inital, + '.')
This code works but I am also trying to make it where if the input lacks a middle name, it still outputs.
I.e. if the input is “James Paul McCartney” the output is “McCartney, J.P” but if the input is “Paul McCartney” The output is “McCartney, P.”
I’ve tried adding another variable full_name3 = ”.join(last_name + ‘, ‘ + first_inital, ‘.’ + middle_inital, + ‘.’)
I’ve tried the code I posted above. Honestly, that is really it, I am super beginner level, and those are the only two avenues I know of.
GriffinsTale is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1