Commit af4c9739 by BellCodeEditor

save project

parent 0cb25c13
Showing with 5 additions and 6 deletions
......@@ -2,11 +2,10 @@
#要求这个函数能接收一个名为num的整型参数
#要求这个函数能计算1+2+3+……+num的结果
def sum_number(num):
if num==1:
def func(n):
if n==1 or n==2:
return 1
else:
return num+sum_number(num-1)
return func(n-1) + func(n-2)
s = sum_number(5)
print(s)
\ No newline at end of file
print(func(36))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment