Help on 11/13 stuck for dayss


#1

shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3
def compute_bill(food):
    total= 0
    for item in food:
        total += prices[item]
    return total

Return Indentation 8/9
#2

I was stuck on this too. I actually just used your code and it worked. My guess it that you just had it indented incorrectly. This is the correct format:

def compute_bill(food):
    total = 0
    for item in food:
        total += prices[item]
    return total

#3

chers boss :smiley: this helped me loads


#4

you can use the "</>" button to format your code:

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

#5

same problem - thanks


#6

I dont understand why py knows which is the food list if we never defined it? Can someone clarify it for me? like each of the steps of the commands and how py interprets it? thanks!


#7

i used this as an alternative, as unsure how py works out what's in your shopping list from the argument food!? Anyway, what i did worked as well:

def compute_bill(shopping_list):
total = 0
for item in shopping_list:
total += prices[item]

return total

#8

thanks I was stuck on this one too (-:


#9

I think they either need to be more clear with the example here, or there is just a bug in this exercise. Maybe both. I got frustrated so I deleted my code and just ran the template that was there from the start and got the same error message for a function that was no longer on the screen. Also I do want to thank sproggy for posting the answer here otherwise it may have been alot longer for me to figure this out.


#10

Hi j_b_d,

The problem with the code is that, here -

prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3

you are missing a closing brace }.