A day at the supermarket - keeping track of the produce (ERROR MESSAGE)


#1


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

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

the result in the console is as follows:but gives an error indicating the orange print out is incorrect while the code appears to be correct: the code is indicated below.

orange
prices: 1.5
stock: 32
pear
prices: 3
stock: 15
banana
prices: 4
stock: 6
apple
prices: 2
stock: 0
None


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


#2

from the 2nd instruction
Print the answer in the following format:

apple
price: 2
stock: 0

now check your code

apple
prices: 2
stock: 0

it should be exact match


#3

Thanks alot.. i rectified the small mistake. it worked.
But then why does such a small error on my part (spacing in this case) affect the functioning of whole program?


#4

In your own environment you can do whatever you want but here you have to do what you are told to do.sometimes even a single space. here STC (sysyem checker) checks whether you've done or haven't what you are told.

so your code just fine .dont worry about it :slight_smile:

not just space.extra character :slight_smile:


#5

Thank You:)) .It's helpful to know that


#6

The code as listed works just fine for the exercise

But, isn't it still incorrect? Shouldn't the call for the string (%s) actually be a call for an integer (%i) or, in the case of the oranges a float (%f)?

I was stuck on this for a while because I thought using the %s would be incorrect.


#7

your print is "price:2"
it should be "price: 2"
so it is "prices: %s" % prices[key]
not "prices:%s" % prices[key]


#8

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