Commit b41a7a92 by BellCodeEditor

auto save

parent 40eb12f4
Showing with 16 additions and 0 deletions
def peach(n):
if n==10:
return 1 #终止递归
num=(peach(n+1)+1)*2
return num
\ No newline at end of file
...@@ -3,3 +3,13 @@ ...@@ -3,3 +3,13 @@
#要求这个函数能计算1+2+3+……+num的结果 #要求这个函数能计算1+2+3+……+num的结果
def sum_numbers(num):
if num==1:
return 1 #终止递归
temp=sum_numbers(num-1) #100=(100-1)
return temp+num#100+99+98.....1
resule=sum_numbers(2)
print(resule) #5050
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