You are getting an error in the second call (jimi Hendrix)
because
jimi as first name amd Hendrix as middle name.
You can define the function with variables, like:
because
get_formatted_name(first_name, middle_name, last_name)requires 3 arguments, as presented, there are only 2, so this function sees
jimi as first name amd Hendrix as middle name.
You can define the function with variables, like:
def get_formatted_name(first_name=None, middle_name=None, last_name=None):and call with:
musician = get_formatted_name(first_name='john', middle_name='lee', last_name='hooker') musician = get_formatted_name(first_name='jimi', last_name='hendrix')that corrects the argument problem, but now you have to check for None in all fields:
def get_formatted_name(first_name=None, middle_name=None, last_name=None): full_name = None if first_name is not None: first_name = first_name if middle_name is not None: full_name = full_name + ' ' + middle_name if last_name is not None: full_name = full_name + ' ' + last_name return full_name