My professor has asked our class to write a Python function that does as following:
Draw a regular n-pointed star with side d - in a function named star(turtle, n, d)
Here's the code that I have so far:
def star(turtle, n, d):
angle = (180-((180*(n-2))/n))*2
for i in range(n):
t.forward(d)
t.left(angle)
return angle
The problem that I am experiencing is that my function is only able to draw stars with odd numbers of corners (5, 7, 9-sided stars). When I ask it to draw a star with an even number of sides, it outputs polygon with sides n/2. So asking to draw an 8-sided star outputs a square, 6-sided gives a triangle, and so forth.
I've tried altering the angle formula many times, but it never works with any given n.
Thanks for helping!