Python 计算圆周率的近似值:使用 while 循环和莱布尼茨公式
pi = 0 i = 1 sign = 1
while abs(1/i) >= 0.00001: pi += sign * (1/i) i += 2 sign *= -1
pi *= 4 print('pi=%.2f' % pi)
原文地址: https://www.cveoy.top/t/topic/qTh 著作权归作者所有。请勿转载和采集!
安全问答是一个知识全球问答,包含丰富的问答知识
pi = 0 i = 1 sign = 1
while abs(1/i) >= 0.00001: pi += sign * (1/i) i += 2 sign *= -1
pi *= 4 print('pi=%.2f' % pi)
原文地址: https://www.cveoy.top/t/topic/qTh 著作权归作者所有。请勿转载和采集!