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 key in prices:
print "apple"
print "Prices: %s" % prices["apple"]
print "Stock: %s" % stock["apple"]

hi can any one help me solving this program. when I click on save&submit it i got out put like this

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!


#2

your dictionary's, why did you give them an uppercase first letter? this should be lowercase

the problem is here:

print "Prices: 
print "Stock

this should be price (without s at the end) and stock (case sensitive)


#3

Hi. i kept small letters for "price" and "stock". but i am not getting program wright. could u send me correct program.

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

when i click on save&submit i got like this.

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

could any one help me in solving this program.


#4

your for loop:

for key in prices:

thanks to your for loop, key will hold all fruits (in turn) and you need to print the results of all fruits, so use key instead of "apple"


#5

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

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

}

for key in prices:

print "price: %s" % prices[key]
print "stock: %s" % stock[key]

As per you instructions I had written code this is the output

Oops, try again. You should have exactly three print statements! (Make sure there are no occurrences of 'print' in any comment or string!)


#6

you should print the product, which is in key

like you did here:

print "apple"

except then with key, so that you print the right product name with stock and price information


#7

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

out put is this

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


#8

the print serves as example, the rest of my reply explains what you actually should print


#9

can any on forward correct program for me


#10

you want to print the name of the product along with the stock and price information

what contains the name of the product? key, very good, so i recommend you to print that.

And no, posting answers and asking for them is not according to the guidelines


#11

You have to print the key, bracked.
With "apple" you only have a string witch loops for each item.


#12

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