Python: A day at the supermaket the "Orange problem"!


Hello everyone,
I can't understant what is going wrong with my code. Can anyone help me please?

This is my code:

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15}

for fruit in prices:
print "the fruit is: %s" % fruit
print "price: %s" % prices[fruit]
print "stock: %s" % stock[fruit]

But i get an error "Oops, try again. Check what your code prints for orange. It doesn't look quite right!"

The thing is, it does look right!!! It prints everything correctly. HEEELP!

Replace this line with your code.



#python books and number of pages.

books = {
       "Automate the Boring Stuff with Python" : 504 ,
       "Invent Your Own Computer Games with Python" : 400,
       "Python Crash Course" : 560

If you loop throught it.
for bok_name in books:
    print(book_name) #It will print keys of dictionary
    print(books[book_name]) #It will print values of dictionary

Lets see your code:
for fruit in prices:
    print "the fruit is: %s" % fruit 
    print "price: %s" % prices[fruit]
    print "stock: %s" % stock[fruit]

Here line:
  print "the fruit is: %s" % fruit 
#They're asking to just print the name of fruit not  "the fruit is: %s" % fruit
#replace your code with
print  fruit

It works!


There's an example of what the output should look like in the instructions, your format is a little different (one should not be able to tell the difference at all, they should be identical)


Hello again!!
Sorry, i did exactly what you said but nothing!!
I can not understant what is happening with my code.
Thank you anyway!


Be suspicious whenever somebody dumps code with the note "it works"

Your output should be exactly the same as what's described in the instructions. The example in the instructions is for apple, so you can compare that character-by-character to what you print for apple. There are even tools for doing such comparisons, online ones as well. You should be able to spot it by eye though, it's a significant difference.


the problem is prices ur printing plural for prices


Thanks i fixed it and it works now!!!


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