Learn

To add a single key: value pair to a dictionary, we can use the syntax:

dictionary[key] = value

For example, if we had our menu dictionary from the first exercise:

menu = {"oatmeal": 3, "avocado toast": 6, "carrot juice": 5, "blueberry muffin": 2}

And we wanted to add a new item, "cheesecake" for 8 dollars, we could use:

menu["cheesecake"] = 8

Now, menu looks like:

{"oatmeal": 3, "avocado toast": 6, "carrot juice": 5, "blueberry muffin": 2, "cheesecake": 8}

Instructions

1.

Create an empty dictionary called animals_in_zoo.

2.

Walking around the zoo, you see 8 zebras. Add "zebras" to animals_in_zoo as a key with a value of 8.

3.

The primate house was bananas! Add "monkeys" to animals_in_zoo as a key with a value of 12.

4.

As you leave the zoo, you are saddened that you did not see any dinosaurs. Add "dinosaurs" to animals_in_zoo as a key with a value of 0.

5.

Print animals_in_zoo.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?