Jan-12-2017, 06:47 AM
I searched the internet for syntax errors but I just get a general definition of what a syntax error could be. I am new to Python and teaching myself via online lessons and meet ups in my area. I have this lesson that should print 2 simple lines which are lines 4 and 9 but only line 4 prints and with a syntax error it looks like and Line 9 does not even appear. Line 9 ( print "This should run.") is a three letter sentence and it is spelled correctly and the spaces are correct and I even retyped it three times. I typed the missing Line 9 code in a code validator that I found online and the line of code was validated as being correct. I use Atom as my editor. Below is what I enter in Atom and I will also show what the results are in Terminal. I've tried self help to see why only line 4 prints but cannot figure out why line 9 will not print if it is typed correctly. I've read this code backwards and forwards but it doesn't come out right. I typed it slow and checked the spacing.
This is what I type in Atom
# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.
print "I could have code like this." and the comma after is ignored
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print "This should run."
This is what I get in Terminal
Renays-MacBook-Pro:mystuff renayjohnson$ cd thestuffa
Renays-MacBook-Pro:thestuffa renayjohnson$ python ex2.py
File "ex2.py", line 4
print "I could have code like this." and the comma after is ignored
^
SyntaxError: invalid syntax
Renays-MacBook-Pro:thestuffa renayjohnson$
This is what I type in Atom
# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.
print "I could have code like this." and the comma after is ignored
# You can also use a comment to "disable" or comment out a piece of code:
# print "This won't run."
print "This should run."
This is what I get in Terminal
Renays-MacBook-Pro:mystuff renayjohnson$ cd thestuffa
Renays-MacBook-Pro:thestuffa renayjohnson$ python ex2.py
File "ex2.py", line 4
print "I could have code like this." and the comma after is ignored
^
SyntaxError: invalid syntax
Renays-MacBook-Pro:thestuffa renayjohnson$