Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
count done
  • Loading branch information
CaiIsProgrammer committed Oct 11, 2019
commit af7517e79ea901081bd498e664e68022f7bac00b
23 changes: 19 additions & 4 deletions recursive_count_th/count_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@
Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters.
Your function must utilize recursion. It cannot contain any loops.
'''

def count_th(word):

# TBC

pass
result = [0,0]
split = list(word)
if(len(split) > 2):
recursion_th(word,result);
elif(len(word) == 2):
if(word == 'th'):
result[1] = 1
return result[1]

def recursion_th(word,result):
if(result[0]+1 != len(word)):
check = str(word[result[0]] + word[result[0]+1]);
if(check == 'th'):
result[1] += 1
result[0] += 1
recursion_th(word,result)
else:
return result