Keeping Track of the Produce


#1



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


I'm not sure what is wrong. I keep getting an error message "Oops, try again. Check what your code prints for orange. It doesn't look quite right!". I've compared my code to other questions in the forum and I can't figure out where the error is.


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

I'm having the exact same issue here and code is formatted the same. There is no hint button or extra help for this module I've noticed.


#3

It's super annoying :confused:
I don't want to assume there is a bug in the websites code but I'm starting to feel like that's the problem. I swear it let me pass through this section when I went through this exercise previously


#4

I think the issue with your code possibly is that it has a space before the colon here:

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


#5

codecademy confirmed that it is a bug in t,

try changing the value of price of orange to 15
also use %d

i wrote this code and it worked!

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

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

for item in prices:
print item
print "price: %d" %(prices[item])
print "stock: %d" %(stock[item])

regards,
Ashutosh Barot


#6

in the original code ,which is asked by datablaster04291,

epsilon22222 is right!
print the colon without space..


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


the bug is ,
when we print value of orange prince =1.5 and use %.2f. to print it .. it throws an error

Note:I reported this bug to codecademy support team,they will resolve it soon!

Enjoy!

regards,
Ashutosh Barot


#7

Thanks for your help!!


#8

thank you so much for your help!!


#9

*** GOT IT TO WORK*** Thanks for the posts.

Hi All -
Has anybody been able to complete this task. I keep getting the "You should have exactly three Print statements!" error. Here is my code:
prices = {"banana": 4,"apple": 2,"orange": 1.5,"pear": 3}

stock = {"banana": 6,"apple": 0,"orange": 32,"pear": 15}
for key in stock:
print key
print "Price:%d" % prices[key]
print "Stock:%d" % stock[key]


#11

My "Price" and "Stock" were capital letters. It worked with all lowercase.

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]


#12

thank you very much!


#13

A few problems I noticed in here were:

the print out for "price" and "stock" need to be lower case.

the %s someone mentioned should have been replaced with a %d which is incorrect. You want the output to be 1.5 for oranges. This needs to be done as a string so %s is correct. The below code is correct and prints out correctly with the decimal for oranges because it prints as a string.

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

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

for item in prices:
print item
print "price: %s" % prices[item]
print "stock: %s" % stock[item]


#14

The problem I found was the string for prices.

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

The above doesn't work, and unusually comes back with the following error 'Oops, try again. Check what your code prints for orange. It doesn't look quite right!'

If I change 'prices' to 'price' it works.

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

#15

hi, everybody
the code print 'price: %d' doesn't print the decimal place of orange, so i code as this:
for key in stock:
print key
if type(prices[key]) == float:
print 'price: %.1f \nstock: %d' % (prices[key], stock[key])
else:
print 'price: %d \nstock: %d' % (prices[key], stock[key])

it prints right in console window, but the program asked me to check the code for orange, i'm confused what's wrong here, too.
bug?


#16

this is not working for me


#17

you got it right - spot on - some sort of BUG -
it took me a while - crap


#18

Hello,

Here's what the final code would look like;

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

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

for item in prices:
    print item
    print "price: %s" % prices[item]
    print "stock: %s" % stock[item]

This should solve the problem of the decimal in the oranges, because we are treating them as a string

@robertomitrofan
@sheelps
@joanzi
@sheepstir
@singingswitchman


#19

It seems this website isn't managed by a supercomputer or an AI, so we've gotto give answers that are in the code, else the program doesn't recognise. For example, if the answer in the program is : print 'hi' and a user inputs: print 'Hi' instead, an error pops up because the program wasn't written to adapt to different answers.
:slight_smile:


#20

thanks a lot :slight_smile:


#21

Wow, that's actually what fixed mine as well.