Investing in stock. Whats wrong?


#1

prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6
"apple": 0
"orange": 32
"pear": 15
}
getting the error File "python", line 9
"apple": 0
^
SyntaxError: invalid syntax
not sure what is wrong. It looks the same as all the others. help is appreciated Thanks.


#2

Hi @degibson ,

You are missing the commas that are needed to delimit the items in this dictionary ...

stock = {
"banana": 6
"apple": 0
"orange": 32
"pear": 15
}

... for example ...

"banana": 6,

#3

Hi,
I am facing similar issue.
my code is
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]

And i Get the error "Oops, try again. Check what your code prints for orange. It doesn't look quite right"

please help


#4

Hi @vijay_b_ramgmail_com ,

Because the code that you posted is not formatted, it is difficult for other users to read and debug it. After code has been pasted into the editing window for posting, you can format it by selecting it, and then by clicking the </> button above the editing area. Alternatively, you can place three backquotes on the line before the code and three backquotes on the line after the code. This will enable us to see important details, such as the indentation and underscores. If you use the backquotes, your code will be color-coded, making it especially easy to read.

In these two lines, you have specified that spaces be placed before the two colons in the output ...

print "price : %s" % prices[key]
print "stock : %s" % stock[key]

... but those spaces are not consistent with the format specified in the instructions.


#5

Should look like this!

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