Skip to content

Instantly share code, notes, and snippets.

@BurhanH
Created February 22, 2019 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurhanH/b7cf31befb9c52eabbb7b58c84dec8ca to your computer and use it in GitHub Desktop.
Save BurhanH/b7cf31befb9c52eabbb7b58c84dec8ca to your computer and use it in GitHub Desktop.
recursion examples. Fibonacci sequence and Factorial sequence
# -*- coding: utf-8 -*-
def fib(n):
if n < 2:
return 1
return fib(n-1) + fib(n-2)
print(fib(6))
# 13
def factorial(n):
if n < 2:
return 1
return n * factorial(n-1)
print(factorial(3))
# 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment