Exercise 9-10 - A Day at the Supermarket


#1



Hey there! I'm having a bit of trouble with exercise 9:

Here's the link: https://www.codecademy.com/courses/python-beginner-en-IZ9Ra/1/4?curriculum_id=4f89dab3d788890003000096#


My program throws this error here: Oops, try again. It looks like your code did not print the correct total.

Any help is appreciated.


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


#2

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

key ? but your iteration variable is items?


#3

Wew lad, it's always something simple. Thanks for pointing that out! My code works now.


#4

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