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}


#1



lesson/12 stocking out
rodando o program, resultado impresso no console coreto,mas da aviso de erro
dizendo que stock pemanece ugual inicio.


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}


estoque inicial
{'orange': 32, 'pear': 15, 'banana': 6, 'apple': 0}
compra
{'pear': 1, 'banana': 1, 'apple': 1}
apple-quant:0
estoque depois da venda
{'orange': 32, 'pear': 14, 'banana': 5, 'apple': 0}
7


Replace this line with your code. 
shopping_list = ["banana", "orange", "apple"]

stock = {
    "banana": 6,
    "apple": 0,
    "orange": 32,
    "pear": 15
}
    
prices = {
    "banana": 4,
    "apple": 2,
    "orange": 1.5,
    "pear": 3    
}

# Write your code below!

def compute_bill(food):
   print "estoque inicial"
   print stock    
   total=0
   print "compra"
   print 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,stock[m]) 
   print "estoque depois da venda"
   print stock      
   return total
print compute_bill({'banana':1,'apple':1,'pear':1})


#2

Using copied code we do not fully understand is not a very good way to learn, or ask for help. It's only too obvious that the OP did not read the instructions. Did you believe that we would not recognize our own code?

Suggest go back to the beginning and complete this on your own, without relying on someone else's solution.


#3

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