Keeping Track of the Produce


#1



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


Oops, try again. Check what your code prints for orange. It doesn't look quite right!


It should read:
apple
price: 2
stock: 0


prices = {"banana":4, "apple":2, "orange":1.5, "pear":3}

stock = {"banana":6, "apple":0, "orange":32, "pear":15}

for x in prices:
    for x in prices:
        if x == "apple":
            print x
    print "Prices: %s" % prices["apple"]
    print "Stock: %s" % stock["apple"]


#2

You want the program to go through each item so you don't need an "if" statement:

for x in prices:
for x in prices: (delete this line)
if x == "apple": (delete this line)
print x ( unindent this line)
print "Prices: %s" % prices["apple"]
print "Stock: %s" % stock["apple"]


#3

You want the program to go through each item so you don't need an "if" statement:

for x in prices:
for x in prices: (delete this line)
if x == "apple": (delete this line)
        print x ( unindent this line one time so it is lined up with your last two print commands}
    print "Prices: %s" % prices["apple"]
    print "Stock: %s" % stock["apple"]

#4

thank you, i adjusted the code to the below and am getting an error code:
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

prices = {"banana":4, "apple":2, "orange":1.5, "pear":3}

stock = {"banana":6, "apple":0, "orange":32, "pear":15}

for x in prices:
print x
print "Prices: %s" % prices["apple"]
print "Stock: %s" % stock["apple"]


#5

I think I got it now but its telling my "Check what your code prints for orange. It doesn't look quite right!"

Code:

prices = {"banana":4, "apple":2, "orange":1.5, "pear":3}

stock = {"banana":6, "apple":0, "orange":32, "pear":15}

for key in prices:
print key
print "Prices: %s" % prices[key]
print "Stock: %s" % stock[key]

output:

orange
Prices: 1.5
Stock: 32
pear
Prices: 3
Stock: 15
banana
Prices: 4
Stock: 6
apple
Prices: 2
Stock: 0
None


#6

same here with my code too. I have no idea how to fix it


#7

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