I generally use loops when solving problems that do the same thing over and over again. I’s starting to use recursion when when a small part of the problem resembles the whole problem. I think I should think of using recursion more often.
defask_recursively(question):reply=input(question)reply=reply.strip().lower()ifreply=='yes':returnTrueelifreply=='no':returnFalseelse:print('\nPlease answer "yes" or "no". \n')ask_recursively(question)defmain():ask_recursively("Do you understand recursion? \n")if__name__=='__main__':main()
Here’s my attempt at solving the fibonacci sequence using recursion…