Question

In Python3 write a function, given a string, compute recursively the number of times lowercase "hi"...

In Python3 write a function, given a string, compute recursively the number of times lowercase "hi" appears in the string,.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Given below is the code for the function as well code to test the function. PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.
Please do rate the answer if it helped. Thank you.


def countHi(s):
   if len(s) < 2:
       return 0
  
   if s[0:2] == "hi":
       return 1 + countHi(s[2:])
   else:
       return countHi(s[1:])
      

#testing the function

s = "12hi abc hixyz hi"
print(countHi(s))

Add a comment
Know the answer?
Add Answer to:
In Python3 write a function, given a string, compute recursively the number of times lowercase "hi"...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT