8. Keeping Track of Produce


#1



Hello. This code was throwing the error "Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)"

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

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

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

for fruit in prices:
    print fruit
    print prices[fruit]
    print "prices: %s" % prices[fruit]
    print "stock: %s" % stock[fruit]

Thanks.


#2

You've got one print statement too many.

In this question they ask for:
* The item name
* The item price
* The amount of stock of this item

And what you give is:
* The item name
* Price
* The item price
* The amount of stock of this item


#3

just remove
print prices[fruit]


#4

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

you dont need to write this one : print prices[fruit]


#5

Wondering if someone can give me a pointer. I have the following 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 "Price: %s" % prices[key]
print "Stock: %s" % stock[key]

It compiles with no errors in the window but I get a messages stating; "Oops, try again. Check what your code prints for orange. It doesn't look quite right!". Any ideas what I may be doing wrong?


#6

This is another case of the answer checking being a bit too sensitive.
Price and Stock shouldn't have capital letters in this excersise. (it's by the print statement)


#7

Thanks for the analysis. You are totally correct. changed the caps to lower case and it works. Good to know. Thanks.


#8

A post was split to a new topic: 8. keeping trace of product