从6-1的累加算法
1 def sum(num):
2 """" 6+5+4+3+2+1 的递归算法"""
3 if num == 1:
4 return num
5 print(num)
6 print("- " * 30)
7 result = num + sum(num - 1)
8 # print(result)
9 return result
10
11
12 print("=" * 60)
13 print(sum(6))
14 print("=" * 60)
15
16 print()
17 print()
18 print()
19
20 从1-6的累加算法
21 def sum1(num):
22 """ 1+2+3+4+5+6 的递归算法"""
23 if num == 6:
24 return num
25
26 print(num)
27 print("- " * 30)
28 ret = num + sum1(num + 1)
29 return (ret)
30 print(ret)
31
32
33 print("=" * 60)
34 print(sum1(1))
35 print("=" * 60)