import turtle

def goto_bounded(t, x, y, x_max, y_max):
    """ Go to position (x, y), unless it falls outside the box
    from (-max_x, -max_y) to (max_x, max_y), in which case
    the turtle should not move.
    Returns True if the turtle ended at (x,y), or False
    if it stayed where it was. """
    
    if x > x_max or y > y_max or x < -x_max or y < -y_max:
        return False
 
    t.goto(x, y)
    return True

def box(t, height, width):
    """ Use turtle t to draw a box with the given height and width.
    Height and width are defined assuming "up" is to the turtle's left.
    The box is drawn counter-clockwise, and the turtle ends in the same
    pose as it started. """
    for i in range(2):
        t.forward(width)
        t.left(90)
        t.forward(height)
        t.left(90)
    

def stairs(t, steps, step_height, step_width):
    """ Draw a staircase using turtle t. The bottom of the first step is where
    the turtle is currently facing. The staircase has num_steps steps, and each
    step is step_width wide and rises step_height above the previous one.
    Postcondition: the turtle is in the same position and orientation as it
    started."""
    for i in range(1, steps+1):
        box(t, step_height * i, step_width)
        t.forward(step_width)

    t.backward(step_width*steps)
    
if __name__ == "__main__":
    t = turtle.Turtle()
    
    stairs(t, 8, 30, 50)
    
    turtle.done()
    