A Day at the Supermarket: Keeping Track of the Produce


#1



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

can you tell me whats wrong with the code.
its giving me this: 
Oops, try again. Check what your code prints for orange. It doesn't look quite right!

according to me everything is fine. Please point whats wrong in the code


#2

This exercise is very strict about formatting.

Your one of the o/p should look like this..

orange
price: 1.5
stock: 32

Can you find any difference ?


#3

Thank you so much, I figured it out.


#4

add space between % and stock[item]


#5

There is already spaces and also printing stock details two times?
(also the problem has been solved?)


#6

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]

total = 0
for key in prices:

value = prices[key]*stock[key]
print value

total +=  value

print total**strong text**


#7

use this line instead of your's
print "price: %s" % prices[item]


#8

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