Q:

Manipulating Strings to return concatenated username

Whenever I try to display the Firstname with first initial attached to the end, I get an out of string index range error!
def ForeName():
    return raw_input("Please enter your Forename: ")

def MiddleName():
    return raw_input("please enter your middle name, if none leave blank: ")

def LastName():
    return raw_input("Please enter your last name: ")

def Test():
    ForeNameT = ForeName()
    MiddleNameT = MiddleName()
    LastNameT = LastName()
    if not MiddleNameT:
        first_username = ForeNameT[0:] + LastNameT[0]
    elif ForeNameT:
         first_username = ForeNameT[0:][0] #i want to display the first name with the initial of the first name attached to the end of the first name.
    else:
        first_username = ForeNameT[0:] + MiddleNameT[0]

    return first_username

print Test()

A:

You can add an argument to Test function by doing def Test(name_method): and then set if to if name_method == 'without_middlename':.
Try to figure out yourself what you would change print Test() to.

