sys.getrecursionlimit()
sys.setrecursionlimit(limit)
实验代码展示:
# import sys # sys.setrecursionlimit(99999) def accumulativeSum(N): if N <= 1: return 1 else: return N+accumulativeSum(N-1) print(accumulativeSum(1998))
Windows PowerShell 版权所有 (C) Microsoft Corporation。保留所有权利。 尝试新的跨平台 PowerShell https://aka.ms/pscore6 加载个人及系统配置文件用了 724 毫秒。 (base) PS C:UserschenxuqiDesktopnewstest> & 'D:Python37python.exe' 'c:Userschenxuqi.vscodeextensionsms-python.python-2021.10.1365161279pythonFileslibpythondebugpylauncher' '9778' '--' 'c:UserschenxuqiDesktopnewstesta.py' Traceback (most recent call last): File "c:UserschenxuqiDesktopnewstesta.py", line 10, inprint(accumulativeSum(1998)) File "c:UserschenxuqiDesktopnewstesta.py", line 8, in accumulativeSum return N+accumulativeSum(N-1) File "c:UserschenxuqiDesktopnewstesta.py", line 8, in accumulativeSum return N+accumulativeSum(N-1) File "c:UserschenxuqiDesktopnewstesta.py", line 8, in accumulativeSum return N+accumulativeSum(N-1) [Previous line repeated 995 more times] File "c:UserschenxuqiDesktopnewstesta.py", line 5, in accumulativeSum if N <= 1: RecursionError: maximum recursion depth exceeded in comparison (base) PS C:UserschenxuqiDesktopnewstest>
实验代码展示:
import sys sys.setrecursionlimit(99999) def accumulativeSum(N): if N <= 1: return 1 else: return N+accumulativeSum(N-1) print(accumulativeSum(1998))
控制台结果输出:
Windows PowerShell 版权所有 (C) Microsoft Corporation。保留所有权利。 尝试新的跨平台 PowerShell https://aka.ms/pscore6 加载个人及系统配置文件用了 753 毫秒。 (base) PS C:UserschenxuqiDesktopnewstest> & 'D:Python37python.exe' 'c:Userschenxuqi.vscodeextensionsms-python.python-2021.10.1365161279pythonFileslibpythondebugpylauncher' '9768' '--' 'c:UserschenxuqiDesktopnewstesta.py' 1997001 (base) PS C:UserschenxuqiDesktopnewstest>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)