-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflexy-polygons.py
More file actions
35 lines (30 loc) · 804 Bytes
/
flexy-polygons.py
File metadata and controls
35 lines (30 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import turtle
turtle.bgcolor('black')
turtle.pensize(2)
def line(length, angle, sides):
for x in range(sides):
turtle.left(angle)
turtle.forward(length)
turtle.speed(2)
turtle.color("white", "black")
a=input('Enter the name of the equilateral polygon you want the program to draw (triangle, square, pentagon, hexagon, heptagon, octagon): ')
if a=='triangle':
line(60, 120, 3)
elif a=='square':
line(45, 90, 4)
elif a=='pentagon':
line(36, 72, 5)
elif a=='hexagon':
line(30, 60, 6)
elif a=='heptagon':
line(25.71428571428571428571, 51.42857142857142857142, 7)
elif a=='octagon':
line(22.5, 45, 8)
else:
s=input('How many sides does this shape have? ')
t=int(s)
x=(180/t)
y=(360/t)
line(x, y, t)
turtle.hideturtle()
turtle.exitonclick()