Commit d656113f by BellCodeEditor

auto save

parent 215d52dc
Showing with 15 additions and 0 deletions
# 1、定义一个递归函数,函数名自取;
# 1、定义一个递归函数,函数名自取;
# 2、能够接收一个num的整数参数
# 3、函数能计算1+2+3+4....num的结果
# 如果定义的函数为func(num),那么func(num)=num + func(num-1);
# 当num等于1的时候,func(1)返回值为1
def sum_number(num):
if num==1:
return 1
p=sum_number(num-1)
return num+p
result=sum_number(100)
print(result)
\ 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