Loop patchwork in python3
Question: I need to create a patchwork in Python 3. All I have left to do is create a
loop which makes the design border the graphics window. I know I need a for
loop however I am not sure how to do this.

This is what I have so far:

    
    
    from graphics import *
    
    def main():
        height = eval(input("What is the height of the window"))
        width = eval(input("What is the width of the window"))
        colour = input("enter the colour of the patch")
        win = GraphWin("Patch", 100*width, 100*height)
        boat_x = 0
        boat_y = 0
        for x in range (4):
             boat(win, boat_x, boat_y, colour)
             boat_x = boat_x + 23
        for i in range(height * 5):
             boat(win, boat_x, boat_y, colour)
             boat_x = boat_x + 24
        for j in range(height * 5):
             boat(win, boat_x, boat_y, colour)
             boat_y = boat_y + 100
        win.getMouse()
        win.close()
    
    
    
    def boat(win, x, y, colour):
        body1 = Polygon(Point(1+x,95+y), Point(5+x,100+y),
                    Point(20+x,100+y), Point(24+x,95+y))
        body1.draw(win)
        line1 = Line(Point(13+x,95+y), Point(13+x,90+y))
        line1.draw(win)
        sail1 = Polygon(Point(1+x,90+y), Point(24+x,90+y), Point(13+x, 73+y))
        sail1.setFill(colour)
        sail1.draw(win)
        body2 = Polygon(Point(1+x, 63), Point(5+x, 68),
                            Point(20+x,68), Point(24+x,63))
        body2.draw(win)
        line2 = Line(Point(13+x,63), Point(13+x,58))
        line2.draw(win)
        sail2 = Polygon(Point(1+x,58), Point(24+x, 58), Point(13+x,40))
        sail2.setFill(colour)
        sail2.draw(win)
        body3 = Polygon(Point(1+x,28), Point(5+x,33),
                            Point(20+x,33), Point(24+x, 28))
        body3.draw(win)
        line3 = Polygon(Point(13+x,28), Point(13+x,23))
        line3.draw(win)
        sail3 = Polygon(Point(1+x,23), Point(24+x, 23), Point(13+x, 5))
        sail3.setFill(colour)
        sail3.draw(win)
    
    main()
    

So far this creates the top border but nothing else. I am also aware that the
boat function isn't the most efficient way of drawing


Answer: When you say that you need to "make the design border the graphics window" I
assume you want your `boat` design to be repeated several times along each
edge of the window (that is, the top, bottom, left and right).

This should be doable in two loops. One will draw the top and bottom edges,
the other two will draw the left and right edges. I'm not too sure how your
drawing code works, so I'm guessing at some offsets here:

    
    
    top = 0
    bottom = (height-1) * 100
    
    for x in range(0, width*100, 25):
        boat(x, top, colour)
        boat(x, bottom, colour)
    
    left = 0
    right = width * 100 - 25
    
    for y in range(100, (height-1)*100, 100):
        boat(left, y, colour)
        boat(right, y, colour)
    

This should call your `boat` subroutine every 25 pixels across the top and
bottom, and every 100 pixels along the left and right edges. Adjust the `top`,
`bottom`, `left` and `right` values and the parameters in the `range` calls in
the loops to make the spacing suit your needs (I just made it up). This code
avoids drawing the corner items twice, though depending on how the drawing
routine works that might not be necessary.

