Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python code doesn't work after imported from PyCharm to Repl.it (ParseError: bad input)

I was working on a simple one-point perspective 3D-Engine in PyCharm which uses Turtle to render images. The code simply just renders three (badly-made) stars floating around and changing colours. I’ve also worked on the site repl.it tons of hours before, and thought that I would "upload" my code there so that I could continue working on it online from other places when I got time. But it seems as if there were a difference between the two compilers in PyCharm and Repl.it: The exact same code that works fine in PyCharm just spits out a Compiler Error in Repl.it. The exact error is ParseError: bad input on line 59 which is really annoying. Here below is the code. I don’t expect anyone to read all the code, but rather just take a quick look at that specific line to see if it’s just me being a moron. Just a heads up, it’s very long!

    import turtle
    import time
    import math

    turtle.getscreen()
    turtle.colormode(255)
    turtle.bgcolor(0, 0, 0)
    turtle.pensize(7)
    turtle.speed(99)


    def draw_line(start_x, start_y, start_z, end_x, end_y, end_z, shift_x, shift_y, shift_z):
        fov = 10
        turtle.penup()
        print("Drawing Line -- First pos: " + str(fov*((start_x+shift_x)/(start_z+shift_z))) + ", Second pos: " + str(fov*((start_y+shift_y)/(start_z+shift_z))))
        turtle.goto(fov*((start_x+shift_x)/(start_z+shift_z)), fov*((start_y+shift_y)/(start_z+shift_z)))
        turtle.pendown()
        turtle.goto(fov*((end_x+shift_x)/(end_z+shift_z)), fov*((end_y+shift_y)/(end_z+shift_z)))
        turtle.penup()


    def draw_star(pos_x, pos_y, pos_z):
        turtle.tracer(0, 0)

        draw_line(-10, -10, 1,  0, 10, 1,  pos_x, pos_y, pos_z)
        draw_line(0, 10, 1,  10, -10, 1, pos_x, pos_y, pos_z)
        draw_line(10, -10, 1,  -10, 3, 1, pos_x, pos_y, pos_z)
        draw_line(-10, 3, 1,  10, 3, 1, pos_x, pos_y, pos_z)
        draw_line(10, 3, 1, -10, -10, 1, pos_x, pos_y, pos_z)

        draw_line(-10, -10, 1.1,  0, 10, 1.1,  pos_x, pos_y, pos_z)
        draw_line(0, 10, 1.1,  10, -10, 1.1, pos_x, pos_y, pos_z)
        draw_line(10, -10, 1.1,  -10, 3, 1.1, pos_x, pos_y, pos_z)
        draw_line(-10, 3, 1.1,  10, 3, 1.1, pos_x, pos_y, pos_z)
        draw_line(10, 3, 1.1, -10, -10, 1.1, pos_x, pos_y, pos_z)

        draw_line(-10, -10, 1, -10, -10, 1.1, pos_x, pos_y, pos_z)
        draw_line(0, 10, 1,  0, 10, 1.1, pos_x, pos_y, pos_z)
        draw_line(10, -10, 1,  10, -10, 1.1,  pos_x, pos_y, pos_z)
        draw_line(-10, 3, 1, -10, 3, 1.1, pos_x, pos_y, pos_z)
        draw_line(10, 3, 1,  10, 3, 1.1, pos_x, pos_y, pos_z)
        print("Finished drawing star at " + str(pos_x) + " " + str(pos_y) + " " + str(pos_z))

        turtle.update()


    i = 0
    i2 = 0
    i3 = 0
    clr = 0
    back = False

    while True:
        turtle.clear()

        valuelist = [math.cos(i/1.2), math.cos(i2/1.2), math.cos(i3/1.2)]
        sortedlist = sorted(valuelist)

        match (sortedlist.index(valuelist[len(valuelist) - 3])):
            case 0:
                turtle.pencolor(clr, 255-clr, clr)
                turtle.pensize(5-(math.cos(i/1.2)*3))
                draw_star(math.cos(i)*10-30, math.sin(i)*10, math.cos(i/1.2)/3)
            case 1:
                turtle.pencolor(255-clr, clr, clr)
                turtle.pensize(5 - (math.cos(i2 / 1.2) * 3))
                draw_star(math.cos(i2)*10, math.sin(i2)*10, math.cos(i2/1.2)/3)
            case 2:
                turtle.pencolor(clr, 255-clr, clr)
                turtle.pensize(5 - (math.cos(i3 / 1.2) * 3))
                draw_star(math.cos(i3)*10+30, math.sin(i3)*10, math.cos(i3/1.2)/3)

        match (sortedlist.index(valuelist[len(valuelist) - 2])):
            case 0:
                turtle.pencolor(clr, 255 - clr, clr)
                turtle.pensize(5 - (math.cos(i / 1.2) * 3))
                draw_star(math.cos(i) * 10 - 30, math.sin(i) * 10, math.cos(i / 1.2) / 3)
            case 1:
                turtle.pencolor(255 - clr, clr, clr)
                turtle.pensize(5 - (math.cos(i2 / 1.2) * 3))
                draw_star(math.cos(i2) * 10, math.sin(i2) * 10, math.cos(i2 / 1.2) / 3)
            case 2:
                turtle.pencolor(clr, 255 - clr, clr)
                turtle.pensize(5 - (math.cos(i3 / 1.2) * 3))
                draw_star(math.cos(i3) * 10 + 30, math.sin(i3) * 10, math.cos(i3 / 1.2) / 3)

        match (sortedlist.index(valuelist[len(valuelist) - 1])):
            case 0:
                turtle.pencolor(clr, 255 - clr, clr)
                turtle.pensize(5 - (math.cos(i / 1.2) * 3))
                draw_star(math.cos(i) * 10 - 30, math.sin(i) * 10, math.cos(i / 1.2) / 3)
            case 1:
                turtle.pencolor(255 - clr, clr, clr)
                turtle.pensize(5 - (math.cos(i2 / 1.2) * 3))
                draw_star(math.cos(i2) * 10, math.sin(i2) * 10, math.cos(i2 / 1.2) / 3)
            case 2:
                turtle.pencolor(clr, 255 - clr, clr)
                turtle.pensize(5 - (math.cos(i3 / 1.2) * 3))
                draw_star(math.cos(i3) * 10 + 30, math.sin(i3) * 10, math.cos(i3 / 1.2) / 3)

        i = i + 0.2
        i2 = i2 - 0.25
        i3 = i3 + 0.3

        if clr > 245:
            back = True

        if clr < 15:
            back = False

        if back:
            clr = clr - 15
        else:
            clr = clr + 15

        time.sleep(0.1)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Python’s match syntax is new with python version 3.10. If the interpreter you’re submitting this to is an earlier version you’ll get a SyntaxError on line 59.

Note that version 3.10 just came out 2 months ago. This is still bleeding-edge syntax.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading