Created
February 22, 2019 18:09
-
-
Save BurhanH/b7cf31befb9c52eabbb7b58c84dec8ca to your computer and use it in GitHub Desktop.
recursion examples. Fibonacci sequence and Factorial sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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