Commit ed98e649 by BellCodeEditor

auto save

parent 53304126
Showing with 19 additions and 7 deletions
def func(num):
if num == 1:
return 1
return num * func(num - 1)
print(func(5))
print(1*2*3*4*5)
\ No newline at end of file
'''
任务目标
1、定义一个递归函数,函数名自取;
2、能够接收一个num的整数参数
3、函数能计算1+2+3+4....num的结果
如果定义的函数为func(num),那么func(num)=
num + func(num-1);当num等于1的时候,func(1)返回值为1
'''
def func(num):
if num == 1:
return 1
value = num + func(num-1)
return value
print(func(10))
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