A day at a supermarket printing total


#1

i need help with this


#2

@webcoder65860,

BEFORE your FOR-IN loop
initialize total
total = 0

Then within your FOR-IN loop
- remove the code-line
total = 0

Add 4 spaces to the code line
total= total + price


#3

prices = {
    "banana" : 4,
    "apple"  : 2,
    "orange" : 1.5,
    "pear"   : 3,
}
stock = {
    "banana" : 6,
    "apple"  : 0,
    "orange" : 32,
    "pear"   : 15,
}
total = 0
for key in prices:
    print key
    print "price: %s" % prices[key]
    print "stock: %s" % stock[key]
    total = prices[key] * stock[key] + total
print total

#4

@coursepro12839,

You are forgetting to print the number Value
for each price*stock ...


#5

@leonhard_wettengmx_n Code academy says it's right :confused:


#6

it worked thank you :smile:


#7

thanks for your solution :smile:


#8

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

for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
total = 0
for m in prices:
t1= prices[m] * stock[m]
print t1
total=total+ t1
print total