Control Flow: The for Loops

Rectangles with Offset

More than one for loop can be nested in a single for loop:

def draw_rectangle_with_offset(width_of_rectangle, height_of_rectangle, offset_of_rectangle):

    for h in range(height_of_rectangle):
        for o in range(1, offset_of_rectangle):
            print(" ", end='')

        for w in range(width_of_rectangle):
            print("#", end='')
        print()


width = 3
height = 5
offset = 5

draw_rectangle_with_offset(width, height, offset)

Output:

     ###
     ###
     ###
     ###
     ###   

Exercise: Print the same rectangle with offset using a single for loop.