mardi 10 juillet 2018

Why I am getting Traceback most recent call last and file string at line 6

My python code is below. when I run this code in compiler every single time I'm getting an error like this below

Traceback (most recent call last): File "main.py", line 4, in turtle.setup(850, 850) File "", line 6, in setup File "/usr/lib64/python2.7/lib-tk/turtle.py", line 3553, in Screen Turtle._screen = _Screen() File "/usr/lib64/python2.7/lib-tk/turtle.py", line 3569, in init _Screen._root = self._root = _Root() File "/usr/lib64/python2.7/lib-tk/turtle.py", line 458, in init TK.Tk.init(self) File "/usr/lib64/python2.7/lib-tk/Tkinter.py", line 1820, in init self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) _tkinter.TclError: no display name and no $DISPLAY environment variable

import random
import turtle

turtle.setup(850, 850)
turtle.penup()
turtle.speed('fastest')
turtle.tracer(0, 0)

x = 0
y = 0

for i in range(1, 16000):
    r = random.uniform(0, 1)

    if r < 0.1:
        nextX = 0
        nextY = float(0.16 * y)

        x = nextX
        y = nextY

    elif r < 0.88:
        nextX = float(0.85 * x * 0.04 * y)
        nextY = float(-0.04 * x * 0.85 * y + 1.6)

        x = nextX
        y = nextY

    elif r < 0.93:
        nextX = float(0.20 * x * -0.26 * y)
        nextY = float(0.23 * x * 0.22 * y + 1.6)

        x = nextX
        y = nextY

    else:
        nextX = float(-0.15 * x * 0.28 * y)
        nextY = float(0.26 * x * 0.24 * y + 0.44)

        x = nextX
        y = nextY    


    turtle.goto(x*40, y*40)
    turtle.dot(2, 'green')

turtle.done()




Aucun commentaire:

Enregistrer un commentaire