Something of Value -> Incorrect total, but whyiiii :)


#1



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


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


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 number in prices:
    multiply = int(prices[number]) * int(stock[number])
    print multiply
    total = total + multiply
    
print total

Any ideas? Thanks a lot in advance.


#2

Why do you need the int for? "orange" has a price of 1.5. Your int will change that to 1 which is not the correct price.


#3

Bright mind, dude! That's the point. Thanks!


#4

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