# Stocking Out

#1

Oops, try again.
calling compute_bill with a list containing 2 apples, 2 pears, 1
orange and 7 bananas resulted in 35.5 instead of the correct 31.5

tenho testado varias combinação de exercicios e no console o resultado estã OK mas recebo mensagem com o valor esperado mas o programa fica em loop enão avança sendo o codigo, ameu ver correto, e nãcosigo passar para a proxima lição.

Porque!
onde esta o erro.

``````Replace this line with your code.
shopping_list ={"banana":7, "pear":2, "orange":1,"apple":2}

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 m in food:

if stock[m]>0 and stock[m]>= shopping_list[m]:
total+=prices[m]* shopping_list[m]
elif stock[m]< shopping_list[m]:
total+=prices[m] * stock[m]

else:
print m+'-quant:'+str(stock[m])
print compute_bill(shopping_list)``````

#2

We could start by simplying the expression and referring to the principal argument, `food`...

Poderíamos começar por simplying a expressão e referindo-se ao principal argumento, `food` ...

``````for m in food:
if stock[m] >= food[m]:
total += prices[m] * food[m]
stock[m] -= food[m]
elif stock[m]:
total += prices[m] * stock[m]
stock[m] = 0
else:
print "%s -quant: %s" % (m, str(stock[m]))``````

This printed,

``````apple -quant: 0
31.5``````

Aside;

I am a little confused because it does not match with the English lesson 12 or 13. Please post a link to the the exercise. Thanks.

Estou um pouco confuso, porque ele não coincide com a lição Inglês 12 ou 13. Por favor, postar um link para o exercício. Obrigado.

#3

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