Someting of Value-help


#1

I can't get to continue in the "something of value"

link to the exercise that I'm stuck at.
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."

I was expecting to get 'total' from my code. Don't understand why it is not printing it correctly. Please, any help or suggestions? Thanks, it is greatly appreciated.


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


#2

this line:

total = 0

declaring total inside the loop means that total gets resetted to zero every time. So what you add tot toal, won't be accumalated. I would declare total before the loop

then print total outside/after the loop


#3

That was it??:open_mouth:

Thanks a lot @stetim94 ! it worked. Hilarious!! :joy:


#4

yea, that was it. But the difficulty is to find the problem and understand why its wrong, and how to fix it. I pretty much did all those steps for you now


#5

Yeah, that's true. I didn't figure what was happened with "total". I totally got blinded in that part. Big confusion there. Thanks once again


#6