Somthing of value / a day at the supermarket


#1

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]
    for key in prices:
        value = prices[key] * stock[key] 
    print value
print total

#2

we need to calculate the total worth of the entire stock

currently, value will just gets assigned a new value each iteration of the loop, not adding to the value already stored in value variable


#3

sorry I still don't understand how do we calculate bit I must of forgotten in the previous lesson


#4

why did make a second loop? That was not necessary.

well, you still need to add value to total, you miss this step


#5

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