In [1]:
numbers = [1.5, 2.3, 0.7, -0.001, 4.4]
total = 0.0
for n in numbers:
    assert n > 0.0, 'Data should only contain positive values'
    total += n
print 'total is:', total


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-1-05f073e92646> in <module>()
      2 total = 0.0
      3 for n in numbers:
----> 4     assert n > 0.0, 'Data should only contain positive values'
      5     total += n
      6 print 'total is:', total

AssertionError: Data should only contain positive values

In [2]:
def normalize_rectangle(rect):
    # Normalizes a rectangle so that it is at the origin and 1.0 units
    # long on its longest axis.
    assert len(rect) == 4, 'Rectangles must contain 4 coordinates'
    x0, y0, x1, y1 = rect
    assert x0 < x1, 'Invalid X coordinates'
    assert y0 < y1, 'Invalid Y coordinates'
    
    dx = x1-x0
    dy = y1-y0
    if dx > dy:
        scaled = float(dx)/dy
        upper_x, upper_y = 1.0, scaled
    else:
        scaled = float(dx)/dy
        upper_x, upper_y = scaled, 1.0

    assert 0 < upper_x <= 1.0, 'Calculated upper X coordinate invalid'
    assert 0 < upper_y <= 1.0, 'Calculated upper Y coordinate invalid'
    
    return (0, 0, upper_x, upper_y)

In [3]:
print normalize_rectangle((0.0,1.0,2.0))


---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-3-921dd524ff9b> in <module>()
----> 1 print normalize_rectangle((0.0,1.0,2.0))

<ipython-input-2-9ad077207dd6> in normalize_rectangle(rect)
      2     # Normalizes a rectangle so that it is at the origin and 1.0 units
      3     # long on its longest axis.
----> 4     assert len(rect) == 4, 'Rectangles must contain 4 coordinates'
      5     x0, y0, x1, y1 = rect
      6     assert x0 < x1, 'Invalid X coordinates'

AssertionError: Rectangles must contain 4 coordinates

In [ ]: