code: def to_polar(x, y, theta_units="radians"):
      
      assert theta_units in [
          "radians",
          "degrees",
      ], "kwarg theta_units must specified in radians or degrees"
  
      theta = atan2(y, x)
      r = sqrt(x ** 2 + y ** 2)
  
      if theta_units == "degrees":
          theta = to_degrees(theta)
  
      return r, theta
docs: Converts cartesian x, y to polar r, theta.