Python draw n-pointed star with turtle graphics -
my professor has asked our class write python function following:
draw regular n-pointed star side d - in function named star(turtle, n, d)
here's code have far:
def star(turtle, n, d): angle = (180-((180*(n-2))/n))*2 in range(n): t.forward(d) t.left(angle) homecoming angle
the problem experiencing function able draw stars odd numbers of corners (5, 7, 9-sided stars). when inquire draw star number of sides, outputs polygon sides n/2. asking draw 8-sided star outputs square, 6-sided gives triangle, , forth.
i've tried altering angle formula many times, never works given n.
thanks helping!
your formula wrong little:
def star(turtle, n, d): in range(n): angle = 180.0 - 180.0 / n turtle.forward(d) turtle.right(angle) turtle.forward(d)
python turtle-graphics
No comments:
Post a Comment