Why do I keep getting this error?- Something of Value


#1



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

Traceback (most recent call last):
File "python", line 20, in
KeyError: 1

Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: 1


I don't know.


Replace this line with your code. 
total = 0
for i in prices: 
    total = total + (prices[1]*stock[1])


#2

This is supposed to be for each key in prices, so instead of 1, it should be i in your total equation.

total = total + prices[i] * stock[i]

#3

Thank you! I guess I thought 1 was i for some weird reason!


#4

You're welcome. :slight_smile:


#5

do u actually work for codecademy, btw?


#6

Nope, very few people on the Forum actually work for Codecademy. :slight_smile:


#7

another code able like this:

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

#8

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