How to draw a polygon of n sides, m times
Question: I'm new in Python programming and I'm having a task to develop a simple
program that draws a polygon of n sides, m times, making the leftmost edge of
the next polygon touch the rightmost edge of the previous polygon. The code
below draws a polygon depending on the number of sides the user inputs and the
number of times the polygon should appear.

    
    
    import turtle
    
    def myTurtle():
      num_side = raw_input("Enter the number of sides: " )
      num_shap = raw_input("Enter the number of shapes: " )
      num_sides = int(num_side)
      num_shape = int(num_shap)
      window = turtle.Screen()
      window.bgcolor("red")
    
      polygon = turtle.Turtle()
      polygon.penup()
      polygon.goto(-200, 200)
      polygon.pendown()
      side_length = 60
      angle = 360.0 // num_sides 
      n = 0
    
      for j in range(0, num_shape):
        polygon.forward(side_length)
        for i in range(num_sides):
            polygon.pencolor("black")
            polygon.forward(side_length)
            polygon.right(angle)
        n += side_length    
    window.exitonclick()
    
    myTurtle()
    

The problem I'm having now is to make the next polygon go next to the previous
polygon.

* * *

I have been able to come up with a better but still not a perfect solution.
Just some polygon that are touching each other. How can i achieve this?

    
    
    import turtle, math
    
    def find_lenth(radius, sides):
      angle = float(360 / sides)
      otherangle = float((180 - angle) / 2)
      radangle = float(angle * (math.pi / 180))
      radangle2 = float(otherangle * (math.pi/180))
      angles = math.sin(radangle) / math.sin(radangle2)
      lenth = radius * angles
      return lenth    
    
    def myTurtle():
      num_side = raw_input("Enter the number of sides: " )
      num_shap = raw_input("Enter the number of shapes: " )
      num_sides = int(num_side)
      num_shape = int(num_shap)
      window = turtle.Screen()
      window.bgcolor("red")
      polygon = turtle.Turtle()
      radius = 60
      side_length = find_lenth(radius, num_sides)
      angle = 360.0 // num_sides 
      delta = radius*2  #this value you must count
      colors = ['blue','white','black','green']
      for i in range(num_shape):
        polygon.penup()
        polygon.goto(-400+delta*i, 200)
        polygon.pendown()
        polygon.pencolor(colors[i%4])
        n = 0
        for j in range(num_sides):
          polygon.forward(side_length)
          polygon.right(angle)
      window.exitonclick()
    
    if __name__ == '__main__':
      myTurtle()
    


Answer: This code will draw you some polygons. For moving pointer to the right value
of pixels you need to count it.

    
    
    import turtle
    
    def myTurtle():
        num_side = raw_input("Enter the number of sides: " )
        num_shap = raw_input("Enter the number of shapes: " )
        num_sides = int(num_side)
        num_shape = int(num_shap)
        window = turtle.Screen()
        window.bgcolor("red")
        polygon = turtle.Turtle()
        side_length = 60
        angle = 360.0 // num_sides 
        delta = side_length*3  #this value you must count
        colors = ['blue','white','black','green']
        for i in range(num_shape):
            polygon.penup()
            polygon.goto(-400+delta*i, 200)
            polygon.pendown()
            polygon.pencolor(colors[i%4])
            n = 0
            for j in range(num_sides):
                polygon.forward(side_length)
                polygon.right(angle)
        window.exitonclick()
    
    if __name__ == '__main__':
        myTurtle()
    

