Something of value


#1



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


Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: unsupported operand type(s) for *: 'dict' and 'dict'


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 price:
        value = price * stock
        print price
        total = total + value
    print total


#2

That error message spells out the problem pretty well, what information are you missing?


#3

It's ok I fixed it now


#4

Did you remove one of the loops as well? (If you think about what the program is supposed to do, it doesn't involve two loops, just one pass over the keys)

And.. Your code uses a variable that hasn't been defined - you probably created it in an earlier version


#5

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


#6

there is no need for writing print statements . just write the following
total = 0
for key in prices:
total = total + prices[key] * stock[key]
print total


#7

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