Initial commit with refactor
This commit is contained in:
59
Polygon100.py
Executable file
59
Polygon100.py
Executable file
@@ -0,0 +1,59 @@
|
||||
print('**************************************')
|
||||
print ('Welcome to DumbCAD 1.01')
|
||||
print ('A Simple Programme to Draw A Regular Polygon')
|
||||
print ('')
|
||||
|
||||
#get "num_sides"
|
||||
num_sides = int(input("How many sides is the polygon to have: between 3 and 20 ?: "))
|
||||
x = (num_sides)
|
||||
|
||||
#get "length"
|
||||
length = int(input("What is the length of each side ?"))
|
||||
print('')
|
||||
|
||||
# dictionary of names "polynames"
|
||||
polynames = {
|
||||
3 : "Triangle",
|
||||
4 : "Square",
|
||||
5 : "Pentagon",
|
||||
6 : "Hexagon",
|
||||
7 : "Heptagon",
|
||||
8 : "Octagon",
|
||||
9 : "Nonagon",
|
||||
10: "Decagon",
|
||||
11: "Hendecagon",
|
||||
12: "Dodecagon",
|
||||
13: "Triskaidecagon",
|
||||
14: "Tetradecagon",
|
||||
15: "Pendedecagon",
|
||||
16: "Hexdecagon",
|
||||
17: "Heptdecagon",
|
||||
18: "Octdecagon",
|
||||
19: "Enneadecagon",
|
||||
20: "Icosagon",
|
||||
}
|
||||
# use "num_sides" to get "figure_name" from dictionary "polynames"
|
||||
figure_name = polynames[x]
|
||||
|
||||
#calculate internal angle of polygon
|
||||
int_angle = (num_sides-2)*180/num_sides
|
||||
|
||||
print (f'Okay, a {num_sides} sided polygon is called a {figure_name} and it has an internal angles of {int_angle} degrees.')
|
||||
print (f'Lets draw a regular {figure_name} with {length} long sides.')
|
||||
|
||||
import turtle
|
||||
turtle.screensize(4000,4000)
|
||||
turtle.hideturtle()
|
||||
turtle.speed(speed=1)
|
||||
turtle.bgcolor("grey")
|
||||
turtle.pen(pencolor="blue", pensize=5)
|
||||
|
||||
for i in range(num_sides):
|
||||
turtle.forward(length)
|
||||
turtle.left (180 - (int_angle))
|
||||
|
||||
turtle.penup()
|
||||
label=len(figure_name)
|
||||
turtle.goto(-label*9+length/2,-60) #start position for text
|
||||
turtle.write(figure_name, font=("Verdana",25, "normal"))
|
||||
turtle.Screen().exitonclick()
|
||||
Reference in New Issue
Block a user