UNIT 5. 12.Estocando HELP! What i miss?

#1

```````shopping_list = ["banana", "laranja", "maca"]

stock = {
"banana": 6,
"maca": 0,
"laranja": 32,
"pera": 15
}

prices = {
"banana": 4,
"maca": 2,
"laranja": 1.5,
"pera": 3
}

# Escreva seu codigo abaixo!
`def compute_bill(food):
total=0
for food in food:
if stock > 0:
total += food```````

#2

I think the only problem is that you're not returning a result. Just add a `return` statement at the end of your function, and it should be alright .

#3

Nop! =/
`def compute_bill(food): total=0 for food in food: if stock > 0: total += food return total`

Oops, tente outra vez. chamar compute_bill com uma lista contando 1 macas, 1 peras and 1 bananas causou o seguinte erro: unsupported operand type(s) for +=: 'int' and 'str'

#4

Ow, sorry. The problem is that you're using the same variable name twice. You should do two things:

1. Choose a different variable name to loop trough `food`, for instance `item`
2. Find a different way to get the price of the food. When doing the `for in` loop, you're actually looping trough the keys and not the values.

#5

=/ Not working ....
I don't know what to do

#6

Can you post the code that you have right now so we can help you?

#7

Make the following changes to compute_bill function:

While driving along each food item, simply add the price of the item to complete the inventory count stock of the item is greater than zero.
If the item in stock and after adding the price to the total , subtract a stock count stock item.

``````shopping_list = ["banana", "laranja", "maca"]

stock = {
"banana": 6,
"maca": 0,
"laranja": 32,
"pera": 15
}

prices = {
"banana": 4,
"maca": 2,
"laranja": 1.5,
"pera": 3
}

# Escreva seu codigo abaixo!
def compute_bill(food):
total=0
for food in stock:
if stock < 0
total += food

#8

`food` is the list you need to loop trough. You can do that in this way:

``for item in food:``

To get the stock of this `item`, you can do it like this:

``stock[item]``

Also, the `return` should be outside the loop, otherwise it returns immediately.

#9

like that?!

`def compute_bill(food): total=0 for item in food: if stock[intem] < 0 total += food return total`

File "python", line 21
if stock[intem] < 0
SyntaxError: invalid syntax

#10

@nicoekkart
`def compute_bill(food): total=0 for item in food: if stock < 0: total += food return total`
Oops, try again. call compute_bill with a list telling stretchers 1 , 1 and 1 banana pears resulted in 0 instead of the expected 7

#11

I would do it like this:

``````def compute_bill(food):
total=0
for item in food:
if stock[item] > 0:
total += stock[item]