Commit 817521ef by BellCodeEditor

auto save

parent 0f53c1f3
Showing with 18 additions and 0 deletions
#使用递归知识,计算1+2+3+4+...一直到num的和
def sum_numbers(num):
#递归的出口
if num == 1:
return 1
#累加和
n = sum_numbers(num-1)
return n + num
result = sum_numbers(100)
print(result)
# def for_sum(n):
# sum = 0
# for i in range(1,n+1):
# sum += i
# return sum
# result = for_sum(100)
# print(result)
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