Investing in Stock


#1


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

I have followed the instructions of the exercise and I am both getting a syntax error

"File "python", line 3
"apple": 0
^
SyntaxError: invalid syntax"

Along with it returning

"Oops, try again. Did you remember to create a dictionary called stock? "

I do not believe that my code should be acting this way, any and all help will be greatly appreciated.


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


#2

Solved it. My code was lacking the correct commas in my stock.


#3

Could you describe more specifically what "lacking correct commas" mean?
I've met the same problem but can't find a solution.

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

Funny part is that the error is on "apple"

File "python", line 10
"apple": 0
^ (it shows on a quotation mark after apple"
SyntaxError: invalid syntax

So it is fine with quotation marks in "banana".
And i also have another dictionary before "stock" and it seems to work fine.


#4

At the end of the number you need to have commas, so 6, 0, etc to separate the items.

"banana: : 6,

and so on.


#5

I didn't understood your response before, because of linguistic error.
In my native language "commas" also refers sometimes to quotation marks.
And the error I got was also pointing at the quotation mark.
Interesting thing to note in future.

Thank you.


#6

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