Stuck in 10.8. Please help!


#1

Here is the 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 "Srock: %s" % stock[key]
print

Here is the output:
orange
Price: 1.5
Srock: 32

pear
Price: 3
Srock: 15

banana
Price: 4
Srock: 6

apple
Price: 2
Srock: 0

None

This is the error it get:

I'm new to Python and banging my head on the wall to find what the issue is. I've tried rearranging the code, doesn't help.

Can't find anything wrong from what is printed about orange!

Thanks for the help guys.


#2

I've tried the exact same code on a different online IDE.
Comes up without any issue.

Output:
orange
Price: 1.5
Srock: 32

pear
Price: 3
Srock: 15

banana
Price: 4
Srock: 6

apple
Price: 2
Srock: 0

Absolutely lost!!!
Can't move on to the next section!!!!!!!!


#3

After a long time of working it out I found out what it is!!!
I is looking to see if the text is right, you put srock but it should be stock and any variation of that is wrong apparently!

Hope I helped


#4

12whiteleggj,

Thank you so very much for your time and effort on this. Really appreciated.

I've tried your solution but unfortunately, it doesn't solve the problem. I've written and rewritten the code many times and tried may variations of the code with no success.

The annoying thing is, the code works absolutely fine on a different online IDE (http://pythonfiddle.com/ - as you can see from my second post) and I can't move to the next section on codeacademy until this is cleared.

Once again, thank you very very much for your time and efforts on this matter.

Kind Regards.


#5

try this. in prices remove the space after the colon for orange. change srock to stock, remove the capital letters for print price and stock,, write them in small letters. dont make any space before the colon for the print part. these and only these changes worked for me. the rest of your code is correct.


#7

textpro45113,

All I did is change uppercase P and S from Price and Stock to lowercase and it worked!

Now... what I don't understand is... because it is actually a String, why should upper/lowercase be an issue? I might be wrong but in terms of programming, a String can be a combination of any characters as long as there are no escape characters. And that's why the code worked perfectly in another IDE. I guess, it's a codeacademy thing.

Such a relief at last!

Thank you textpro45113 and others who so kindly looked into the issue and spent their time and effots.

Greatly appreciated.