noob: Spider gives me a syntax error on 'good' code, can't figure out why?

69 views
Skip to first unread message

andrew keefe

unread,
Jan 25, 2018, 10:40:25 AM1/25/18
to spyder
Hello,
I'm learning Python from an online course and could not figure out why my super-simple code had a syntax error.  I finally submitted the code I thought was right as the answer to the problem and it was accepted as correct; however, I could never get Spider to execute it. 


bears = {"Grizzly":"angry", "Brown":"friendly", "Polar":"friendly"}
for bear in bears:
    if bears[bear] == "friendly"
        print("Hello, "+bear+" bear!")
    else:
        print("odd")

The question was to come up with correct 'if' statement in line 3.  I thought I was missing something soooooo basic I couldn't see it, but it is correct.  When I tested it in the console it was evaluating correctly, but in the editor...


  File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
    execfile(filename, namespace)

  File "C:\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "F:/directory/delete.py", line 9
    if bears[bear] == "friendly"
                                             ^
SyntaxError: invalid syntax


...and the editor shows a syntax error next to the line number in the editor, too.  It's making me kind of crazy.
Thanks for any help.
A

PmB

unread,
Jan 25, 2018, 11:13:53 AM1/25/18
to spyd...@googlegroups.com

Try

    if bears[bear] == "friendly" :

you're missing : at the end.

--
You received this message because you are subscribed to the Google Groups "spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spyderlib+...@googlegroups.com.
To post to this group, send email to spyd...@googlegroups.com.
Visit this group at https://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/d/optout.

-- 
Peter M. Bloomfield
Physicist,
PET Centre,
Centre for Addiction and Mental Health,
250 College St.,
Toronto, Ontario,
Canada M5T 1R8
Tel: 416 535 8501 Ext. 34243
FAX: 416 979 4656
Reply all
Reply to author
Forward
0 new messages