12. Stocking out. Plz help!


#1



12. Stocking out.


Oops, try again. stock doesn't look quite right! Make sure to not call compute_bill since it changes the stock! It should contain: {'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}


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


#2

You don't need to print anything right now. Therefore remove these lines:
print compute(shopping_list)
print stock


#3

Thanks! But it was still incorrect after deleting these two lines. "Oops, try again. The function compute_bill seems to be missing! Make sure you didn't delete/misspell/overwrite it! "


#4

That's because your function is called compute and not compute_bill


#5

uh... I called it computer because 'Make sure to not call compute_bill since it changes the stock!'


#6

It's saying not to call the function. Meaning don't do this:

compute_bill(shopping_list);

It still wants you to name your function compute_bill.

When you define a function, you are not "calling" it. You are simply defining it and giving it a name.


#7

Okay. So even I did this:
def compute(food):
total=0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] += -1
return total
print compute(shopping_list)

It was not right though:(

oh the posting window does not show the programming layers...


#8

You're misunderstanding. It does not want you to call the function. It wants you to define it and name it compute_bill. Meaning that all it wants you to do is this:

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

#9

ah I see....thanks so much for the patience to answer my question!!! It worked now!


#10

No problem!

P.S. If you want to know how to format the code in your posts please refer to:


#11

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