利用python计算圆球的体积_python中球体的体积

您必须更改:volume = math.pi(n/2)^2/math.gamma(n/2 + 1)

收件人:

^{pr2}$

完整代码:import math

dimension = input("Enter dimension: ")

print("dimension: " + str(dimension))

n = float(dimension)

volume = math.pi**(n/2)/math.gamma(n/2 + 1)

print("Volume: " + str(round(volume,4)))

输入:Enter dimension: 3

输出:dimension: 3

Volume: 4.1888

附加:import math

import matplotlib.pyplot as plt

x = []

y = []

for dimension in range(100):

n = float(dimension)

volume = math.pi**(n/2)/math.gamma(n/2 + 1)

x.append(n)

y.append(volume)

plt.plot(x, y)

plt.show()

你可能感兴趣的:(利用python计算圆球的体积)