Keeping Track of the Produce


#1



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


I keep getting the following error message: Oops, try again. Check what your code prints for orange. It doesn't look quite right!


No error messages!


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 "Price: %s" % prices[key]
    print "Stock: %s" % stock[key]


#2

This is what should be printed for orange:

orange
price: 1.5
stock: 32

This is what your code prints:

orange
Price: 1.5
Stock: 32

Do you see the difference? "Price" and "Stock" should be lowercase :slight_smile:


#3

someone tell me whats wrong with my 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]


#4

Just a typo, in this line:

print "prices: %s" % prices[key]

it should be "price: ...:

print "price: %s" % prices[key]

#5

ty bro......................................


#6

Thanks.
I had the same problem and it was driving me crazy.:slight_smile:


#7

@khaleqi, @sathishsash You're very welcome. Glad I could help :slight_smile:


#8

can you help me with this :confused:
it keeps on asking for orange .

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 "price: %s" % prices[key]
print "apple: %s" % stock[key]


#9

Sure. It should be:

print "stock: %s" % stock[key]

not:

print "apple: %s" % stock[key]

:slight_smile:


#10

oh right _ ! how silly i am ... thank you :slightsmile:


#11

You're very welcome :slight_smile:


#12

Can I get help with my code?
prices = {
"banana":4,
"apple":2,
"orange":1.5,
"pear":3
}

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

for i in prices:
print "%s\nprice: %d\nstock: %d" % (i, prices[i], stock[i])

There's an indent before print it's just not showing.
It returns:
orange
price: 1
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0


#13

Read the error message:

You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)


#15

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 "price: %s " % prices[key]
print "stock: %s " % stock[key]

please help me .


#16

Codecademy does not like extra spaces after %s, you should delete them :slight_smile:


#17

Ah I see. They didn't want me to use string formatting. Thanks


#18

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 "price:%s" %prices[key]
print "stock:%s" %stock[key]

may i know what is problem in my code?


#19

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

i got "SyntaxError: invalid syntax" last line :confused:
if someone could help me it would be cool thank you


#20

There should be a space between colons and the values:

print "price: %s" %prices[key]
print "stock: %s" %stock[key]

#21

If you want to interpolate many values you have to enclose them in the parentheses:

for x in prices :
  print "%s: %d" %(x, prices[x])

But this is not what you want to use in this exercise. You should use three separate print statements.