8.3 Keeping Track of Produce. 2 Solutions that print out the same thing but 1 is wrong, why?


#1

The following code prints out the same as the correct version, but I get the error: "your input for pears is wrong" in this code. And why does it start printing the list with orange? why doesn't it start with banana?

"incorrect" code:

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

correct code:

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


#2

Hello! I've got another code that prints out result that the challenge is looking for, but it still give me an error. Why?

Code is:

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

Try it out and let me know where I made a mistake.
Thanks!


#3

If you want answers to your problem you should make your own post and not hijack someone else's.

Try it out and let me know how it works out.
Thanks!


#4

Your code is right, your spacing is not(The colons in your output). And get rid of the blank print in your code.


#5

Sorry man, I made a mistake..