How are my totals wrong?


I keep getting this error:

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

Why is it saying that its incorrect? They're clearly the correct totals.

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
    a = "%s" % prices[key] 
    b = "%s" % stock[key]
    total = int(float(a) * float(b))
    print total


This is giving individual totals rather than one accumulative total.

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

The end result will be a float so need for us to cast any. We do not want an integer total, but dollars and cents.


I understand now why we don't want an integer total.

But why do you mean one accumulative total? The code gives you the totals for each fruit which is what you want, what do you mean accumulative?

Ok sorry I understand now - total for all food sold. Thank you


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