make bouncing turtle with python
<p>i am a beginner with python
I wrote this code to make bouncing ball with turtle it works but have some erors like ball dissapering</p>

<pre><code>import turtle
turtle.shape("circle")
xdir = 1
x = 1
y = 1
ydir = 1
while True:
     x = x + 3 * xdir
     y = y + 3 * ydir
    turtle.goto(x , y)
    if x &gt;= turtle.window_width():
        xdir = -1
    if x &lt;= -turtle.window_width():
        xdir = 1
    if y &gt;= turtle.window_height():
        ydir = -1
    if y &lt;= -turtle.window_height():
        ydir = 1
    turtle.penup()
turtle.mainloop()
</code></pre>

<p>You need <code>window_width()/2</code> and <code>window_height()/2</code> to keep inside window.</p>

<p>ie.</p>

<pre><code>if x &gt;= turtle.window_width()/2:
    xdir = -1
if x &lt;= -turtle.window_width()/2:
    xdir = 1
if y &gt;= turtle.window_height()/2:
    ydir = -1
if y &lt;= -turtle.window_height()/2:
    ydir = 1
</code></pre>

python turtle-graphics