Hello guys. I need help with this python code

def build_profile(first, last, **user_info):


    """Build a dictionary containing everything we know about user."""

    profile = {}

    profile['first_name'] = first

    profile['last_name'] = last

    for key, value in user_info.items():

        profile[key] = value
    return profile

user_profile = build_profile('albert',  'einstein',
                                                             location='princeton',
                                                             field='physics')

print(user_profile)

output : 
{'first_name': 'albert', 'last_name': 'einstein', 'location': 'princeton', 'field': 'physics'}

I want output:
{‘first_name’: ‘albert’, ‘last_name’: ‘einstein’,
‘location’: ‘princeton’, ‘field’: ‘physics’}

Thank you everyone

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Okay. I am newbie. Thank you

Hey Vanthao,

first of all I am also a absolute beginner in terms of programming and python, but I tried to solve the task and made my own attempt at it.

Here are my thoughts:

For creating a dictonary, i would want to have a unique key that stores all the information of the person in the value as a list, so I created a code aiming for that.

I prompt the user for data, because i dont have a file or anything else as input.

profile = {}
count = 0

while True:
    newprofile = input("Want to create new profile? (y/n): ")
    if newprofile == "y":
        lastname = input("Enter lastname: ")
        surname = input("Enter surname: ")
        location = input("Enter location: ")
        field = input("enter field: ")
        user = lastname[:2] + surname[:2] + str(count) #could blow up, it's just a quick solution
        userinfo = [lastname,surname,location,field]
        profile[user] = userinfo
        count = count + 1
    else:
        break

for key,val in profile.items():
    print(val)

you are in your share. nice one

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.