Something of value


#1

i'm not sure what to do.

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 key in prices:

#2

Create a variable called total and set it to zero.

total = 0

Loop through the prices dictionaries.

for key in prices:

For each key in prices, multiply the number in prices by the number in stock. Print that value into the console and then add it to total.

    total_price = prices[key] * stock[key] # multiply the number in prices by the number in stock
    print total_price # print that value into the console
    total += total_price # add it to total

Finally, outside your loop, print total.

print total

#3

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