Help me please on 11


#1

my code is as follows but i get an error:

menu = {} # Empty dictionary
menu['Chicken Alfredo'] = 14.50 # Adding new key-value pair
print menu['Chicken Alfredo']

menu = ['Taco'] = 10.00
menu = ['Hamburger'] = 17.50
menu = ['Pizza'] = 12.50

print "There are " + str(len(menu)) + " items on the menu."
print menu['Taco']
print menu['Pizza']
print menu['Hamburger']

but the error is:

Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: can't assign to literal (python, line 6)

so can anyone help me.


#2

If I get it correctly, menu is a dictionary, right?
So, how do we assign something to a dictionary?

We use:

menu[yourKey] = yourValue

Doing like:

menu = ['Taco'] = 10.00

Won't actually work, as far as I'm concerned.
You're trying to assign the value of 10.00 to ['Taco'] (which is a list containing a single element which is 'Taco') and later trying to assign it to menu, which is your dictionary.

Try doing this way:

menu['Taco'] = 10.00

Here you're telling Python to "go to my dictionary menu, get/add the entry 'Taco' and set the value of it to 10.00"

Try and fix those issues and see if things execute properly.
If not, let us know! :slight_smile:


#3

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