8. Keeping track of your products Problem!


#1



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?

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


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]


#2

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:

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


#3

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]

#4

thanks for the help :smile:


#5

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