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
Share:
10,344

Related videos on Youtube

lenawb
Author by

lenawb

Updated on May 26, 2022

Comments

  • lenawb
    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
      Payman over 6 years
      sides/360? shouldn't that be 360/sides?
  • lenawb
    lenawb over 6 years
    Thank 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.