8. Keeping track of your products Problem!


I am having trouble with this supermarket for loop code. I have seen everyone else's code and i followed it but it still won't work. Can you please help me?


Oops, try again. Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: unexpected indent (python, line 14)

here is the console error: File "python", line 14
for x in price:
IndentationError: unexpected indent

price = {
    "banana" : 4,
    "apple" : 2,
    "orange" : 1.5,
    "pear" : 3
stock = {
    "banana" : 6,
    "apple" : 0,
    "orange" : 32,
    "pear" : 15
    for x in price:
     print x
     print "price: %s" % price[x]
     print "stock: %s" % stock[x]


The error is stating that there is an indentation in that line of code that should not be there. You indent after a "for" loop, not before:

for loop #(code not indented)
indented code #(4 spaces)


You need to give at least for spaces for indentation for the code to work
give you prints a good indentation and it'll work.

for x in price:
    print x
    print "price: %s" % price[x]
    print "stock: %s" % stock[x]


thanks for the help :smile:


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