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.

Write a PYTHON recursive function to count how many times a character in string. >>> numberofcharacters(\'a,\'america\') 2SolutionAnswer: Here is the s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site