From dbf79b1d6eba8f7f712459f9982736d17f8bb01d Mon Sep 17 00:00:00 2001 From: BellCodeEditor <bellcode_dev@bell.ai> Date: Sun, 5 May 2024 10:39:02 +0800 Subject: [PATCH] save project --- diy1.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/diy1.py b/diy1.py index 0735a44..e65523e 100644 --- a/diy1.py +++ b/diy1.py @@ -1,5 +1,9 @@ -#定义一个函数sum_numbers() -#要求这个函数能接收一个名为num的整型参数 -#要求这个函数能计算1+2+3+……+num的结果 - +def func(n): + if n<=2: + return 1 + elif n>2: + value = func(n-1)+func(n-2) + return value +result = func(5) +print(result) \ No newline at end of file -- libgit2 0.25.0