#9 Something of Value


#1



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


Error message: "Oops, try again. It looks like your code did not print the correct total. "

If you run the code it prints
64
94
106
106
106

Any idea what's happening here? I think it is somehow not going in order. The code from the previous lesson also prints out of order, so I think that may have something to do with it. Any idea why it prints the top Orange, Pear, Banana, Apple? That order seems arbitrary.


My code should start with total = 0, then add the product of price*stock to it each time.

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:
    total = total + prices[cost] * stock[key]
    print total
print total


#2

i get the following error when running your code:

NameError: name 'cost' is not defined

looking at this line:

total = total + prices[cost] * stock[key]

that make sense, cost is defined nowhere? What should you use here?


#3

Arg, so simple.... and it worked just fine now. Thanks!


#4