A Day at the Supermarket: Something of Value


#1



https://www.codecademy.com/en/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096


my total is 117 but I thought my total would be each item's value times the stock, however it shows total value for all items combined... is this correct???


expected individual item totals not total of all items combined


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

for item in prices:
    print item
    print "price: %s" % prices[item]
    print "stock: %s" % stock[item]

total = 0
for item in prices:
    total = prices[item] * stock[item] + total
    
print total


#2

Yes, they want the total of all items combined. Which is 117.
If you want to print each of the fruit's individual total prices, just put print total inside the loop.

EDIT:
Changed a variable name.


#3

Okay I thought I was crazy... Thanks :slight_smile:


#4

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