# 计算PI的值
import itertools
def pi(N):
list1 = []
for value in itertools.count(1, 2):
if value > N:
break
list1.append(value)
list2 = [4 / value if list1.index(value) % 2 == 0 else -4 / value for value in list1 ]
print(list2)
return sum(list2)
if __name__ == '__main__':
value = pi(5000)
print(value)
Python3 粗略计算PI的值
最新推荐文章于 2024-01-04 00:28:23 发布