What wrong is in my code?


#1

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

My code:

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

Consol output:

orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
48.0
45
24
0
117.0
None

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

Please, help me. I don't understand what wrong is in my code.


#2

Your code is correct, but you were supposed not to change the value of prices and stock because codecademy uses these objects to test your code :slight_smile:

So you only have to get rid of this line:

prices[key] *= stock[key]

and add multiplication to the next two lines:

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

#3

thank you very much!


#4

You're very welcome! :slight_smile:


#5

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