Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def tri_recursion(k):
- if(k>0):
- result = k+tri_recursion(k-1)
- print(result)
- else:
- result = 0
- return result
- print("nnRecursion Example Results")
- tri_recursion(6)
- Recursion Example Results
- 1
- 3
- 6
- 10
- 15
- 21
- def tri_recursion(k):
- if(k>0):
- try_recursion_val = tri_recursion(k-1)
- result = k + try_recursion_val
- print(f"At k = {k}, we have tri_recursion(k-1) = {try_recursion_val}")
- else:
- result = 0
- return result
- print("nnRecursion Example Results")
- tri_recursion(6)
- Recursion Example Results
- At k = 1, we have tri_recursion(k-1) = 0
- At k = 2, we have tri_recursion(k-1) = 1
- At k = 3, we have tri_recursion(k-1) = 3
- At k = 4, we have tri_recursion(k-1) = 6
- At k = 5, we have tri_recursion(k-1) = 10
- At k = 6, we have tri_recursion(k-1) = 15
Add Comment
Please, Sign In to add comment