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

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

我在 PyCharm 中开发了一个简单的单点透视 3D 引擎,它使用 Turtle 渲染图像。该代码只是简单地渲染了三颗(制作不当的)星星四处漂浮并改变颜色。我也在 repl.it 之前在网站上工作了很多小时,我想我会把我的代码“上传”到那里,这样我就可以在有时间的时候从其他地方继续在线处理它。但似乎 PyCharm 和 Repl.it 中的两个编译器之间存在差异:在 PyCharm 中运行良好的完全相同的代码只是在 [=17= 中吐出一个编译器错误].确切的错误是 ParseError: bad input on line 59 这真的很烦人。下面是代码。我不希望任何人阅读所有代码,而是快速浏览一下特定行,看看是否只有我是个白痴。 请注意,它很长!

    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)

Python 的 match 语法是 python 3.10 版的新语法。如果您将其提交给的解释器是早期版本,您将在第 59 行收到 SyntaxError。

请注意,3.10 版 2 个月前刚刚发布。这仍然是前沿语法。