import sys
sys.setrecursionlimit(100000)
def fact(x):
if x == 1:
return 1
else :
sign =(-1)**x
return fact(x-1)-sign*(1/(2*x-1))
n=int(input())
print("{:.8f}".format(4*fact(n)))
本来没有前两行,然后当输入2000的时候会出现RecursionError: maximum recursion depth exceeded in comparison
百度了之后修改了一下就加入了前两行 但是为什么到2898和2990的时候就不输出了?
Python 3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:\Users\heyyyguaner\Desktop\学习资料\大一\Python\第一章\作业\week 11\jisuanpaizhi.py
2989
3.14192721
>>>
= RESTART: C:\Users\heyyyguaner\Desktop\学习资料\大一\Python\第一章\作业\week 11\jisuanpaizhi.py
2990
================================ RESTART: Shell ================================
>>>