Something of Value


#1

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

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

Expectation:
Pass.

Summary: I'm encountering this "incorrect total" error even though the total being printed is correct. Is this a real error or an issue of my adding extra code to pretty it up being outside of the exercises expectation? o_O

Code:

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

print "Total Net: %i" % total

What Prints:

orange
price: 1.5
stock: 32

pear
price: 3
stock: 15

banana
price: 4
stock: 6

apple
price: 2
stock: 0

orange
48.0

pear
45

banana
24

apple
0

Total Gross: 117
None


#2

Those lines may be removed. Once your loop is complete, print the total with no embellishment..


#3

Hi mtf, thanks for taking a look. I made the correction you suggested but still got the same error.

I tried a few things.

Ultimately, in removing "Total Gross: %i" % from my 'print total' code, I no longer get the error. But, I don't really know why '"Total Gross: %i" %' had to be removed, the code doesn't look wrong and the error had to do with the printing of the correct total, which wasn't incorrect.


#4

It was the embellishment that caused the fail. There are no parse errors.


#5

Oh I see. I misread what you meant before. Thanks for the help!


#6

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