summaryrefslogtreecommitdiffstats
path: root/fibonacci.py
blob: bf1ea4a5977ddee19438acad19272ad36fe07aee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python

def fibonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fibonacci(n - 1) + fibonacci(n - 2)

# code below will execute only if this .py file is ran directly instead of being imported
if __name__ == "__main__":
    import sys
    if (len(sys.argv) == 2):
        print('fibonacci of ' + str(int(sys.argv[1])) + ' is ' + str(fibonacci(int(sys.argv[1]))));
    else:
        print('usage: fibonacci.py <number>');