e
def calc_e(bais=0.000001):
ret = 1
jie_cheng = 1
i = 1
while True:
last_term = 1.0/jie_cheng
if last_term >= bais:
ret += last_term
i += 1
jie_cheng *= i
else:
return ret
return ret
def main():
ret = calc_e()
print(ret)
if __name__ == '__main__':
main()
π
def calc_pai(bais=0.00001):
ret = 0
sign = 1
odd_num = 1
while True:
last_term = 1.0/odd_num
if last_term >= bais:
ret += last_term*sign
odd_num += 2
sign = -sign
else:
return ret*4
def main():
ret = calc_pai()
print(ret)
if __name__ == '__main__':
main()