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

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

Help needed please!!!


#2

Your final result should be in this format.

Like one of the output should look like this..

banana
price: 4
stock: 6

#3

here u have typed prices instead of price


#4

That is how my code is looking


#5

You have a misspelling there as @e.chamath mentioned.


#6

If i change it to "price" then "price" will not be defined


#7

I was talking about format, You're printing value like this..You don't have to change prices[fruit] to price[fruit].

price: 5


#8

how do i change that??


#9

I found how to do that.Thank you for your help.


#10

I hope it is clear to you that we were just formatting our o/p string using format specifier (%s) and the final output should looked like what I mentioned in my first post.
If this still blurry to you,I will explain.


#11

I understood my mistake.I did not get you in your first post.Thank you for your help.


#13

I'm getting the same error (Oops, try again. Check what your code prints for orange. It doesn't look quite right!).

Here's my code:

create dictionary for prices

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

create stock dictionary

stock={
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
for fruit in prices:
print fruit
print "Price: %s" % prices[fruit]
print "Stock: %s" % stock[fruit]


#14

@tmbaxter
I had the same issue, try using all lower-case for "Price: %s" & "Stock: %s" in the print. Codecademy's platform can be very particular on grammar when it doesn't need to be.


#15

Oh my word. You have GOT to be kidding me. A capital letter for a more readable format broke the code in the print statement?

That fixed it, though . . . Thanks!


#16

prices = {"banana": 4, "apple": 2, "orange": 1.5, "pear": 3}
stock = {"banana": 6, "apple": 0, "orange": 32, "pear": 15}
for n in prices:
print "%s" % n
print "price: %s" % prices[n]
print "stock: %s" % stock[n] + "\n"

DOES NOT WORK FOR ME...what is wrong?


#17

I have all lowercase, price is not prices in quotes, still gives me the same error. Can anyone please help?

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

stock={"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15}
for key in prices:
print "%s " % key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]


#18

I need help too plz:tired_face:


#19

I meant plz :tired_face:


#20

There is extra space ( %s )while printing the key..

print "%s " % key


#21

Nvm i got it thank you guys for the help!! :innocent: