Why invalid syntax (<string>, line 24)?

15,008

Solution 1

You are using python2 and should change:

print(" ", end="")
print("#", end="" )

to:

print(" "),
print("#"),

furthermore

You should probably change:

print() 

to

print("")

And this "beauty" can be reduced by using "\n" which translates rowbreak.

print()
print()
print()
print("I have drawn a pyramid with a height of 0!")
print("Isn't it pretty!")

to:

print("\n\n\nI have drawn a pyramid with a height of 0!\nIsn't it pretty!")

Solution 2

TL;DR: Try install pylint3

sudo apt-get install pylint3

Today I had a nearly identical issue. I wanted to use pyreverse, but the mentioned syntax error message occurred. I have had installed both python2 and python3 so assumed that pyreverse (pylint) was just using python2, so I changed my python symlink (python2 was the default):

sudo ln -sfn /usr/bin/python3.6 /usr/bin/python

But this didn’t help, so I looked if pylint haves pylint3 version and It haves. After installing pylint3 and running pyreverse3 (for your case pylint3) everything runs just fine.

I know this is an old question, but for someone else this could be helpful.

Share:
15,008
wvandertoorn
Author by

wvandertoorn

Updated on June 23, 2022

Comments

  • wvandertoorn
    wvandertoorn almost 2 years

    Super new to Python and I just can't figure out what is causing the error message in my code...

    It says '[pylint] E0001:invalid syntax (<string>, line 24)'.
    

    Could anyone maybe explain what I'm missing here?

    Much thanks!

    #########################################
    # Draws a mario-style right-side-aligned half pyramid 
    # of the requested height.
    # Restriction: 0 < height < 23
    ##########################################
    
    while True:
        height = int(input("Height: "))
        if height > 0 and height < 23:
            break
        elif height == 0:
            print()
            print()
            print()
            print("I have drawn a pyramid with a height of 0!")
            print("Isn't it pretty!")
            exit(0)
    
    hashes = 2
    
    for i in range(height):
        spaces = (height - hashes + 1)
        for j in range(spaces):
            print(" ", end="")
        for k in range(hashes):
            print("#", end="" )
        print()
        hashes += 1