Python Forum
Only one of two lines print/syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Only one of two lines print/syntax error
#1
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$ 
Reply


Messages In This Thread
Only one of two lines print/syntax error - by naysjp - Jan-12-2017, 06:47 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  World Clock syntax error OscarBoots 1 221 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,332 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 447 Jan-19-2024, 01:20 PM
Last Post: rob101
  Syntax error while executing the Python code in Linux DivAsh 8 1,749 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,281 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  print(data) is suddenly invalid syntax db042190 6 1,262 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  syntax error question - string mgallotti 5 1,374 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  Syntax error? I don't see it KenHorse 4 1,333 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 948 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,932 Sep-17-2022, 04:09 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020