Still stuck on 11/13


Okay it has been five hours since I made that other post and I’m still stuck. I’m also just… beyond frustrated. I made a new post because my other one stopped getting replies. Maybe the guy who was helping me is off the clock, but I am going out of my mind and can’t wait until tomorrow to get this over with.

Right now my code looks like this:

  1. I’m pretty sure that parameter food is supposed to reappear somewhere in the function, but I don’t know how, why, or where. The instructions mention a "food list" but I don’t know what that means. Was I supposed to make a food list? Is it referring to shopping_list?
  2. I know return total at the end is going to give me 7.50 because that’s the sum of "banana", "apple", and "orange".
  3. I’m pretty sure I’m not allowed to simply list the individual items and manually add them to total, but that’s the only solution I can come up with, since all the prices are stored in prices. However, I also can’t make a for-loop using prices because it has one too many keys. Maybe there’s some Python sorcery that makes shopping_list interact with the prices dictionary, but if there is I can’t find it in my notes.
  4. I feel like it wants me to somehow incorporate shopping_list but I can’t imagine what I’m supposed to do with it.
  5. I’ve also tried total = total + prices["banana"] + prices["apple"] + prices["orange"] and total = total + prices["banana", "apple", "orange"] and they didn’t work.


The idea of using a loop is so we do not have to use literals in the function.

total = 0
for item in food
    total += prices[item]


I believe that would add the values of all four keys in the prices dictionary to total, but I am only supposed to add three of those four values.

Edit: I thought maybe I had it for a second. I wrote total += prices["banana", "apple", "orange"] but it threw this error:

calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: (‘banana’, ‘apple’, ‘orange’)

2nd edit: I also tried

for x in food:
[indent]total += prices[“banana”]
[indent]total += prices[“apple”]
[indent]total += prices[“orange”]

3rd edit: I gave up and clicked the “Solution” button. The solution does not make sense. This is what the solution looks like:
It just doesn’t make sense. Why is this the solution? prices has four keys in it, and my shopping_list only has three. return total should give me “7.5”, but instead it gives me nothing. Nothing prints to the console at the end of this code.
I’ve been beating my head against the wall over this exercise since 11:30 this morning and it is now 7:20 PM, and the solution I was specifically avoiding because it was definitely wrong turned out to be the right one. It doesn’t make sense. I never would have gotten it, because it could not have been the correct solution. Is this one bugged?


That’s what food contains when you pass in the shopping list.

The full contents of either dictionary is not a factor. We’re not iterating over the dictionary, only the food list. The dictionaries are for look-up purposes, only.


I still don’t understand. We never passed in shopping_list, nowhere in the code.


You would in the call to the function…


Now food will be the shopping_list. It may not be expected in the lesson, so read the instructions carefully.


It’s completely irrelevant where the input to the function comes from. The function should do its job regardless.

Similarly, it isn’t the job of the function to print a result. There’s no reason to expect anything to be printed.

Other things it shouldn’t care about or do: feeding the cat, watching tv, firing nuclear missiles, time of the day


Ohhh man. I finally get that we’re defining a function, not implementing/executing one. It doesn’t have to actually run, it just needs to be able to run if I should hypothetically decide to pass in a list of food items to buy.

Thank you ionatan and mtf! The wave of relief from finally resolving this one felt like morphine.


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