Python Introducing Dictionaries Introducing Dictionaries Creating a Dictionary

Matthew Stafford
PLUS
Matthew Stafford
Courses Plus Student 4,658 Points

Create a dictionary with the following key value pairs: 1) key: 'name', value: '', 2) key: 'topic', value: 'python'. Ass

Create a dictionary with the following key value pairs: 1) key: 'name', value: '', 2) key: 'topic', value: 'python'. Assign this dictionary to a variable called student.

creating_dictionaries.py
student = {'name':''}
student = {'topic':'python'}
print(student())
Gregory St. Clair
Gregory St. Clair
Courses Plus Student 2,001 Points

Hey there :)

You've got a few things sideways here.

first, you assigned student twice, which means student in this case is only a dictionary that contains the topic:python key value pair - because you assigned over it in your code.

What you are looking to do is this: student = { 'name':'', 'topic':'python' }

Do you see how both key value pairs are in the same dictionary, separated by a comma? Next, to call it: print(student)

since student is already declared.

2 Answers

Miranda Chen
Miranda Chen
6,945 Points

Put it all under the student variable. By the way for the value for 'name', it wants you to make " the value Like this:

student = {'name': '"', 'topic' : 'python'}
Greg Heffley
Greg Heffley
6,371 Points
student = {
    "name" : "",
    "topic" : "python"
}

You created a dictionary and then reassigned it with a new dictionary.

Just put them both into the same variable.

Instead of calling print students like a function. ex (your print function), call it like a variable. ex (print(student))

In this example, you do not even need the print function.