Using python turtle to draw a polygon with n number of sides
10,344
you should divide 360 by number of sides not the other way around.
angle = 360 / sides
Related videos on Youtube
Author by
lenawb
Updated on May 26, 2022Comments
-
lenawb almost 2 years
I am new to python with turtle and would appreciate some help. I am trying to create a program that takes an input for a number of sides then draws a regular polygon with that number of sides. However, it either produces a TimeLimitError or it simply draws a straight line.
Here is what I have:
sides = int(input("How many sides would you like? ")) angle = sides / 360 import turtle for count in range(sides): turtle.fd(50) turtle.lt(angle)
But this is what it keeps producing:
How many sides would you like? 5 TimeLimitError: Program exceeded run time limit. on line 1
-
Payman over 6 yearssides/360? shouldn't that be 360/sides?
-
-
lenawb over 6 yearsThank you, that would explain the straight line. I think I was getting more confused with TimeLimitError and as a result didn't spot the obvious mistake.