FAQ: Learn Python: A Day at the Supermarket - Let's Check Out!

This community-built FAQ covers the “Let’s Check Out!” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Let’s Check Out!:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

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

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

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

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

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

print compute_bill(shopping_list)

can someone tell me what this code does this is at the final step of lets check out

Can a function call any dictionary defined outside of function without indexing?

Globally defined dictionaries are accessible from anywhere in the program. We access the dictionary by name, and its values by key name subscript.

Hi
Thanks, Roy.

I figured out by running my program.

Sam

1 Like

Hello I am having major difficulty on what to put for the final line of “Let’s Check Out!”
I can put anything in the command and hit run, and it gives me the option to go to next! For example, I deleted the whole entire code so no code exists, and hit run and it allows me to hit next. There is no way to see what the ‘correct solution’ is.

When I put “print compute_bill(shopping_list)” as the final line, it prints out 5.5, but I thought the purpose of the function compute_bill was to give me the total cost of the fruit I was buying.

Thanks in advance

Have you still got your code? If not, then just do the exercise again without checking the solution. If you run into a problem,post YOUR code, here so we can examine it.

I still have my code. I just want to know what line of code is supposed to be added for 13/13 “Let’s Check Out.” Can you tell me what should be added or maybe provide the correct full code for this problem? As I can not “View Solution” for this problem.
The code I am using is from 12/13 “Stocking out” “View Solution.”

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= 1
return total

Apologies in advance, first time posting and only a few days into coding.
Thank you for your reply.
Regards

We cannot tell whether your code has the correct indentation. If you can still edit your post, select the code sample and click the </> button in the tool tray.

A common error, though we cannot tell, just now, is to return inside the loop. Check that your return statement is not indented too far.

1 Like

Hmm it seems as if the question I am inquiring about is more difficult than expected.
For 13/13, what is supposed to be typed out for the part “1.Print your result and click Run to finish this course.”
The code I am using is from 12/13 “View Solution” verbatim:
def compute_bill(food):
Preformatted texttotal = 0
Preformatted textfor item in food:
Preformatted text``Preformatted textif stock[item] > 0:
Preformatted text``Preformatted text``Preformatted texttotal += prices[item]
Preformatted text``Preformatted text``Preformatted textstock[item] -= 1
Preformatted text return total

Maybe another way to reword my question would be this: If I were to hit “View Solution” what would be presented?

Thanks

Still, I see nothing wrong with the code you posted earlier, apart from the missing indentation and the possibility your return statement is inside the loop so returns on the first iteration. That would explain the result you showed in your earlier post. Rather than focus on the solution code, let’s focus on yours.

We see in your most recent post that you are still learning how to format code samples in posts. You’ve almost got it. Try posting once more, but your code, not the solution.

@sader2 5.5 is the correct answer. the shopping list you use consists of [“banana”, “orange”, “apple”]
apples are not in stock so it will only count the banana and the orange from your list. if you add those 2 you get 5.5.