2020-12-31

having trouble with functions

I need a hand on this, not being able to solve it has been bothering me a lot. Here is my code:

def build_profile(first, last, **user_info): 
    """Build a user's profile dictionary."""  
    profile = {'first': first, 'last': last}

    for key, value in user_info.items():
        profile[key] = value
    return profile

user_0 = build_profile('albert', 'einstein',
        location='princeton')
user_1 = build_profile('marie', 'curie',
        location='paris', field='chemistry')
print(user_0)
print(user_1)
print('\n')

def new_member(name, age, **extra_info):
  """Build a new member's profile"""
  portfolio = {'name': name, 'age': age}

  for key, value in extra_info.items():
    portfolio[key] = value
    return portfolio

member_1 = new_member('vinny geladro', '24', location='alabama')
member_2 = new_member('sally jackson', '28', location='florida', field='biology')
print(member_1)
print(member_2)

I'm new to programming and I have been practicing functions at the moment. The first function (build_profile) is a provided example I found. the second function (new_member) was the one that I wrote to try it out myself.

this is what they both output:

{'first': 'albert', 'last': 'einstein', 'location': 'princeton'}
{'first': 'marie', 'last': 'curie', 'location': 'paris', 'field': 'chemistry'}


{'name': 'vinny geladro', 'age': '24', 'location': 'alabama'}
{'name': 'sally jackson', 'age': '28', 'location': 'florida'}

My issue is that the example function returns both "location" and "field" for Marie Curie, but my function won't return both "location" and "field" for Sally Jackson and I wrote the code practically identical to the example. I'm not sure what I'm doing wrong I've tried rewriting it four different times with different variable names to no avail. I would greatly appreciate the feedback.



from Recent Questions - Stack Overflow https://ift.tt/3n1NzSS
https://ift.tt/eA8V8J

No comments:

Post a Comment