Write a PYTHON recursive function to count how many times a
Write a PYTHON recursive function to count how many times a character in string.
>>> numberofcharacters(\'a,\'america\')
2
Solution
Answer:
Here is the simple recursive code :
def length(s):
if not s:
return 0
else:
return 1+length(s[1:])
This code computes the length of the string recursively.
