3

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
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
wvandertoorn
  • 59
  • 1
  • 1
  • 5

2 Answers2

2

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!")
Anton vBR
  • 18,287
  • 5
  • 40
  • 46
  • Thanks for the tip on style improvement! However I am sure that I'm using Python3. 'import sys; print(sys.version)' returned: 3.6.2 (default, Oct 2 2017, 09:48:04) [GCC 5.4.0 20160609] – wvandertoorn Oct 03 '17 at 13:23
  • 1
    @wvandertoorn That is strange as I have both py2 and py3 and have replicated your error on py2. Your could works fine on 3.6. – Anton vBR Oct 03 '17 at 13:24
  • @wvandertoorn `python3` may be 3.6.2, but what about `pylint`? – trent Oct 03 '17 at 13:58
  • 1
    Also, `from __future__ import print_function` is probably a better way to handle a version mismatch, rather than "fixing" all the `print` calls, assuming the version being used is at least 2.6. – trent Oct 03 '17 at 14:02
  • @trentcl well that is arguable as I was under the assumption he wrote the code in py2. Most likely the problem is something else here though. – Anton vBR Oct 03 '17 at 14:54
  • The question is tagged [python-3.x] so I assumed that Python 3 was intended. Nevertheless, I still advocate for time travel to the future over time travel to the past :) – trent Oct 03 '17 at 15:01
1

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.

Martin
  • 117
  • 1
  • 5
  • Thanks, this fixed my problem by using `pyreverse3`. Probably that would also be good hint in the more general pyreverse questions. – rayon Sep 13 '20 at 08:02