FAQ: A Day at the Supermarket - Investing in Stock

This community-built FAQ covers the "Investing in Stock " exercise from the lesson “A Day at the Supermarket”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Python

FAQs on the exercise _Investing in Stock _

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

" Create a stock dictionary with the values below.

py “banana”: 6, “apple”: 0, “orange”: 32, “pear”: 15

What does the “py” mean here ? I didn’t know so I didn’t include it, and the code ran well. Then I included it and I got a suntax error.

The same question from me. I have identical situation. mynameismisterg did you sort it out?

py was placed in the instruction by mistake. Omit it.

1 Like

Perhaps we’ll learn this later, and if so, “just keep going, you’ll learn it later” will be an acceptable answer, but if not:

Would there be a way to make a dictionary with multiple keys so we don’t have to list the fruit over and over every time we want to give it a new property? Something like, for example:

multikey_product_list = { "product 1": item_number : 8675309 price : 5.00 "product 2": item_number : 4567891 price : 5.99 }

If so, that’d be snazzy. If not, oh well.

Thanks for any insight, I’m enjoying my time here so far :slight_smile:

1 Like

I may be misunderstanding your query but it’s perfectly valid to nest containers so you could have a dictionary where the values of that dictionary were each themselves dictionaries.

data = {
    'a': {1: 'red', 2: 'blue', 3: 'green',},
    'b': {0: 'black', 5: 'red', 3: 'green',},
}

Nesting too deeply can be rather difficult to understand and use after a while though. If you find yourself adding structures within structures always take a moment to see if there’s a better option. A few other containers might be suitable for this purpose too, or you might decide to rewrite part of it using new objects with the class keyword.

1 Like

I suspected classes might be a suggested answer, I have heard of them before. I might play around with your suggestion later and see how useful that is for what I was imagining. Thanks for a response. :slight_smile:

1 Like