# Help in the A day in Supermarket in the exercise nine

#1

Thanks Roy. I have troubles with another exercise.
I need your help in the A day in Supermarket in the exercise nine, I think that my code is perfect but when I seem in the window result the total gives zero. Like this:
45
0
24
48.0
0.
This is the code:
total = 0
for key in precios:
print precios[key] * inventario[key]
total = precios[key] * inventario[key]
print total

Mantener el orden
#2

should be, `total +=`

#3

No it's the same the total gives 48 now:
total = 0
for key in precios:
print precios[key] * inventario[key]
total += precios[key] * inventario[key]
print total

#5

I tried this and passed. Without seeing the indentation in your code it's impossible to tell what the error might be.

``````precios  = {
"banana": 4,
"manzana": 2,
"naranja": 1.5,
"pera": 3
}

inventario = {
"banana" : 6,
"manzana" : 0,
"naranja" : 32,
"pera" : 15
}

total = 0;
for key in precios:
print key
print "precio: %s" % precios[key]
print "inventario: %s" % inventario[key]
total += inventario[key] * precios[key]
print total``````

Output:

``````pera
precio: 3
inventario: 15
manzana
precio: 2
inventario: 0
banana
precio: 4
inventario: 6
naranja
precio: 1.5
inventario: 32
117.0
None``````

#6

Niceeeeee, I appreciate your help. What about the exercise twelve, because the instructions don't have logic about what. I need your help again.
This is the instruction: Hacé lo siguiente para tu función calcular_factura:
01. Mientras recorres cada ítem de comida agregá solamente el precio del ítem al total si la cuenta de los ítems inventario es mayor que cero.
02. Si el ítem está en el inventario y después de que agregás el precio al total, restá uno de la cuenta de ítems de inventario.
My code without tracking:

``````def calcular_factura(comida):
total = 0
for numero in comida:
total += comida[numero]

#7

Did you write a call expression and print the return value?

``print calcular_futura(compras)``

There is also a spelling error in one of the dictionaries. `naranaja` (not yours, the provided code).

#8

Yes I wrote a call expression, this one: if inventario > 0, then I print the return value like this :
print calcular_facturas(compras), but the window results gives this error
Traceback (most recent call last):
File "python", line 20, in
File "python", line 18, in calcular_factura
TypeError: list indices must be integers, not str

#9

``````def calcular_futura(comida):
total = 0
for k in comida:
if inventario[k] > 0:
total += precios[k]

print calcular_futura(compras)``````

#10

Perfect Roy, so now I only need to change comida to precios??? its for understand the code

#11

And I put the code that you give me and the error now says:
File "python", line 19
total += precio[numero]
^
IndentationError: expected an indented block

I have a last question I hope that you can to respond, the instruction in this excersice say what Si el ítem está en el inventario y después de que agregás el precio al total, restá uno de la cuenta de ítems de inventario.
So in the window results don't show me subtracting one from the inventario, this is necessary?

#12

Do as the instructions ask. I left that step off in the hopes you would catch it. Use the variable names given in the lesson.