import mathimport matplotlib.pyplot as plt# 1. 输入固定周长L(可修改)L = float(input("请输入绳子的长度L:"))# 2. 定义边数范围:3到100n_list = range(3, 101)s_list = []# 3. 循环计算每个正n边形的面积for n in n_list: # 正n边形面积公式 s = L ** 2 / (4 * n * math.tan(math.pi / n)) s_list.append(s)# 4. 计算圆的面积(参考值)s_circle = L ** 2 / (4 * math.pi)# 5. 绘制散点图plt.figure(figsize=(10, 6))plt.scatter(n_list, s_list, color='blue', s=20, label='area_of_regular_n-gon')plt.axhline(y=s_circle, color='red', linestyle='--', label=f'area of the circle={s_circle:.2f}')plt.xlabel('the number of sides of a regular n-gonn', fontsize=12)plt.ylabel('area:S', fontsize=12)plt.title(f'when perimeter={L},The relationship between the number of sides and the area of a regular polygon', fontsize=14)plt.legend()plt.grid(True)plt.show()