Chapter-8 Problem in solving "A Day at the Supermarket problem"


#1


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


Expecting a price and stock values displayed on the console


Observed: " Check what your code prints for orange.It doen't look quite right"


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 : %0.1f" % prices[key]
    print "stock : %d" % stock[key]


#2

I really appreciate for your response:):slight_smile:


#3

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

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


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

You write it this way because "stock: %s" % stock[key] in this example, you will change %s in front of stock string into the value that stays after next %s which in our case is stock[key]

Here is an example


#4

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