Hi all. I am having trouble with one of midterm practice problem questions again. I need to be able to get the First, Middle, and Last Name using the count function. However, my professor wants us to be using a name with more than one middle name, and I am having trouble making it print the first name on one line, the full middle name separately on another line, and the last name on another line. Any Help will be greatly appreciated.
Here's my code:
def getFirstName(fullname):
space = fullname.find(' ')
return fullname[0:space]
def getMiddleName(fullname):
count = fullname.count(' ')
temp = fullname
for i in range(count):
space = temp.find(' ')
temp = temp[space-1:]
return temp
def getLastName(fullname):
count = fullname.count(' ')
temp = fullname
for i in range(count):
space = temp.find(' ')
temp = temp[space+1:]
return temp
name = 'Benjamin de OMG I HAVE A LOT OF MIDDLE NAMES la Franklin'
fname = getFirstName(name)
mname = getMiddleName(name)
lname = getLastName(name)
print(fname)
print(mname)
print(lname)
This is what I keep getting for my result:
Benjamin
n de OMG I HAVE A LOT OF MIDDLE NAMES la Franklin
Franklin
>>>
Basically I need it to say:
Benjamin
de OMG I HAVE A LOT OF MIDDLE NAMES la
Franklin
Basically this code needs to print any names between the firstname and the lastname.