print("This program draws pentagons of many colors.") while True: pent_num = int(input("Enter the desired number of pentagons to draw:")) if pent_num <= 0 or pent_num > 30: print("Please enter an integer that is greater than zero and less than 30") continue break import math import turtle n=5 # number or desired shape has length=50 # length turtle moves per side of pentagon sin=(math.sqrt(3)/2) # unit circle coordinate cos=(.5) # unit circle coordinate ext_ang = 180-180*(n-2)/n count = 0 x1= .2 # chosen color % x2= .4 # chosen color % x3= .6 # chosen color % turtle.color(x3,x1,x2) turtle.begin_fill() turtle.penup() turtle.goto(0,2.5*cos*length) # top of unit circle * 2.5 turtle.pendown() while 5 <= pent_num: while count < 5: turtle.forward(length) turtle.left(ext_ang) # n = number of repeated loops count = count + 1 # draws 1+5n pentagon turtle.end_fill() turtle.penup() turtle.goto(sin*length,cos*length) turtle.pendown() count = 0 turtle.color(x3,x2,x1) turtle.begin_fill() while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 # draws 2+5n pentagon turtle.end_fill() turtle.penup() turtle.goto(-sin*length,cos*length) turtle.pendown() count = 0 turtle.color(x1,x3,x2) turtle.begin_fill() while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 # draws 3+5n pentagon turtle.end_fill() turtle.penup() turtle.goto(-sin*length,-cos*length) turtle.pendown() count = 0 turtle.color(x2,x3,x1) turtle.begin_fill() while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 # draws 4+5n pentagon turtle.end_fill() turtle.penup() turtle.goto(sin*length,-cos*length) turtle.pendown() count = 0 turtle.color(x2,x1,x3) turtle.begin_fill() while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 # draws 5+5n pentagon turtle.end_fill() pent_num = pent_num - 5 sin = 1.25*sin # sin multiplier for next loop cos = 1.25*cos # cos multiplier for next loop count= 0 turtle.penup() turtle.goto(0,2.5*cos*length) # new destination for start pentagon of new loop turtle.pendown() x1=x1*.8 # color % multiplier for next loop x2=x2*.3 # color % multiplier for next loop x3=x3*.7 # color % multiplier for next loop turtle.color(x1,x2,x3) turtle.begin_fill() turtle.color(x1,x2,x3) turtle.begin_fill() while 4<= pent_num and pent_num < 5: while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 turtle.end_fill() pent_num = pent_num - 1 turtle.penup() turtle.goto(-sin*length,cos*length) turtle.pendown() count = 0 turtle.color(x1,x3,x2) turtle.begin_fill() while 3<= pent_num and pent_num < 4: while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 turtle.end_fill() pent_num = pent_num - 1 turtle.penup() turtle.goto(-sin*length,-cos*length) turtle.pendown() count = 0 turtle.color(x2,x1,x3) turtle.begin_fill() while 2<= pent_num and pent_num < 3: while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 turtle.end_fill() pent_num = pent_num - 1 turtle.penup() turtle.goto(sin*length,-cos*length) turtle.pendown() count = 0 turtle.color(x2,x3,x1) turtle.begin_fill() while 1<= pent_num and pent_num < 2: while count < 5: turtle.forward(length) turtle.left(ext_ang) count = count + 1 turtle.end_fill() pent_num = pent_num - 1 turtle.penup() turtle.goto(sin*length,cos*length) turtle.pendown() count = 0 print("Thank you for using this program.")