import numpy as np
import math
import matplotlib.pyplot as plt
# x軸を1〜10まで整数ステップにする
x = np.arange(1, 11)
# 各nまでの部分和 Σ(1/k!)
y = [sum(1 / math.factorial(k) for k in range(0, int(n)+1)) for n in x]
plt.plot(x, y, marker='o')
plt.title("部分和: Σ(1/k!) → e に収束する様子")
plt.xlabel("n")
plt.ylabel("部分和の値")
plt.grid(True)
plt.axhline(math.e, color='red', linestyle='--', label='e ≈ 2.71828')
plt.legend()
plt.show()
To embed this project on your website, copy the following code and paste it into your website's HTML: