![]() |
Only one of two lines print/syntax error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Only one of two lines print/syntax error (/thread-1556.html) |
Only one of two lines print/syntax error - naysjp - Jan-12-2017 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$ RE: Only one of two lines print/syntax error - buran - Jan-12-2017 Welcome to the forum. Take your time to read the forum rules. In the future, please use CODE tags around your code print "I could have code like this." and the comma after is ignoredthe part after the closing double-quote is the problem - I assume that's something from your book/tutorial explanations print "I could have code like this." RE: Only one of two lines print/syntax error - wavic - Jan-12-2017 You print what is in the string wrapped in "". All that part ( and the comma after is ignored ) is like you want to print a bunch of variables named and, the, comma, after, is, ignored. You can do that but you have to separate them with a comma. So the right syntax will be:print "I could have code like this.", and, the, comma, after, is, ignored"And", "is" are key words in Python. |