8. Keeping track of the produce


#1

I'm not sure what is wrong with this code, the error coming up is "Check what your code prints for orange. It doesn't look quite right!" When I look at what the code prints, it looks totally fine.

Also, what is the reason for the %s and % on the final two lines

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

the output is case sensitive.

%s serves as a string placeholder for a variable


#3

we encounter the same problem, make 'Price: %s' be 'price: %s' , it works, trust me!


#4

It worked. Thanks
Seems a bit odd though


#5

That fixed it. Thank you

How come it couldn't be

print 'Price: ' prices[key]


#6

the exercise validation is case sensitive, and the output should be an exact match


#7

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