DEV Community

Discussion on: Fibonacci Sequence Function

Collapse
 
ashish_918 profile image
Ashish Pandey

Yes We can do the same with recursion as well.

Code snippet:

def fibonacci_sequence(nterms):

  # Base case
    if nterms == 1:
       return 1
   if nterms == 0:
      return 0

   # recursive call
    return fibonacci_sequence(nterms-1) + fibonacci_sequence(nterms-2)
Enter fullscreen mode Exit fullscreen mode

We can do memomization here as well because here we are doing many rework as well

Some comments have been hidden by the post's author - find out more