You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
numbers= [1.5, 2.3, 0.7, -0.001, 4.4]
total=0.0fornuminnumber:
assertnum>0.0, 'Data should only contain positive values'total+=numprint('total is:', total)
defnormalize_rectangle(rect):
""" Normalizes a rectangle so that it is at the origin and 1.0 units long on its longest axis Input should be of the format (x0, y0, x1, y1). (x0, y0) and (x1, y1) define the lower left and upper right corners of the rectangle, respectively. """assertlen(rect) ==4, 'Rectangles must contain 4 coordinates'x0, y0, x1, y1=rectassertx0<x1, 'Invalid X coordinates'asserty0<y1, 'Invalid Y coordinates'dx=x1-x0dy=y1-y0ifdx>dy:
scaled=dx/dyupper_x, upper_y=1.0, scaledelse:
scaled=dy/dxupper_x, upper_y=scaled, 1.0assert0<upper_x<=1.0, 'Calculated upper X coordinate invalid'assert0<upper_y<=1.0, 'Calculated upper Y coordinate invalid'return (0, 0, upper_x, upper_y)
print(normalize_rectangle( (0.0, 1.0, 2.0) ))
print(normalize_rectangle( (0.0, 0.0, 1.0, 5.0) ))
print(normalize_rectangle( (0.0, 0.0, 5.0, 1.0) ))