Python Programming - Multithreading, OOP, NumPy and Pandas
11. What is recursion
#4 Python Programming Exercise
Construct a recursive function that takes 2 parameters as input - a string and a given index ( of the text). The aim is to visit every character of the text (from left to right - so starting with index 0) recursively.
Good luck!
========================================================
#4 Python Programming Exercise
def process(txt, i):
# base case - when to terminate
if i == len(txt):
return
print(txt[i])
# hop to the next character in the text
process(txt, i+1)
This is the so-called tail recursion. We
===================================================
نظرات