Keeping Track of the Produce


#1



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


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


#2

prices[fruit] itself is not a string, it's an integer.

The way I did it was without using the %, I converted them to string with the str() function.

Furthermore they asked you to print the answer in this format:

apple
price: 2
stock: 0

But you did it this way:

print "prices: "
print "stock: "
print fruit

#3

I have figured that they want price not prices


#4

Thanks for updating. After testing, I realized %s automatically converts the integer to string. So there is more than 1 way of doing it.:slight_smile:


#5

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

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


#6

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