how to draw a star and a circle in python turtle

Solutions on MaxInterview for how to draw a star and a circle in python turtle by the best coders in the world

showing results for - "how to draw a star and a circle in python turtle"
Edoardo
26 Feb 2016
1import turtle, time
2
3t = turtle.Turtle()
4t.shape("turtle")  # you could also change our turtle to a pen.
5t.color("red")  # the pen/turtle's color will now draw in red.
6t.speed(0)  # 0 means that the picture is done immediately, 1 is slowest, 2 faster etc.
7
8
9def draw_star():
10	for x in range(0,5):  # repeats 5 times
11		t.left(72)
12		t.forward(100)
13		t.right(144)
14		t.forward(100)
15
16
17def draw_circle():
18	t.circle(75)  # luckily turtle already has a function to draw a circle. The
19    			  # 75 indicates that the radius (or diameter, idk) is 75 pixels.
20
21draw_star()  # calling the function to draw a star
22
23time.sleep(2)  # we wait 2 secs before erasing
24t.clear()
25t.penup()
26t.home()
27t.pendown()
28
29draw_star()
30