import json points = [(0.1, 0.2), (0.5, 0.5), (0.2, 0.9), (0.9, 0.1), (0.8, 0.7), (0.4, 0.7), (0.95, 0.95), (0.7, 0.3)] # 坐标在单位正方形内,x²+y²≤1 的点也在其四分之一单位圆内。 hits = sum(x * x + y * y <= 1 for x, y in points) ratio = hits / len(points) # 该四分之一圆的面积为 π/4,乘以 4 还原 π。 estimate = 4 * ratio assert hits == 6 and estimate == 3 result = {"hits": hits, "ratio": ratio, "pi_estimate": estimate} print("LAB_RESULT " + json.dumps(result, ensure_ascii=False))