Keeping Track of the Produce


#1

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

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

I have been trying this program for couple of hours. i was unable to solve this program. can any one help me to solve it.


#2

There's an example in the instructions, you can compare that to the corresponding part of your output. They are slightly different.

You can also read the output and take note of that the English grammar isn't right in what you print.


#3

You have defined the iterator variable, key but are not using it. Try using the key so you can iterate the entire dictionary, not just 'apple'.


#4

Hi,
As per instructions give out put must be as follows''

apple
price: 2
stock: 0

To get this out put i had written the code as follows:

for Key in prices:
print "apple"
print "prices: %s" % prices["apple"]
print "stock: %s" % stock["apple"]

For this code i got output as follows

apple
prices: 2
stock: 0
apple
prices: 2
stock: 0
apple
prices: 2
stock: 0
apple
prices: 2
stock: 0
None

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

Could any one send me correct program.


#5

As @ionatan mentioned, it is an example to model your own output by. Not to be taken literally.

Why would you want to iterate a dictionary only to print out the same literal keys and values in every iteration? Why not make use the the key variable?


#6

And then you can compare what you wrote to the example.

They are different. Read them, compare them. Compare them exactly, being similar at a glance is not the same as being exactly the same.


#8

3 posts were split to a new topic: Check what your code prints for orange


#10