PythonUncategorized

Fibonacci Series – Python

[sourcecode language=”python” wraplines=”false” collapse=”false”]
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 15 23:54:44 2016

@author: Shruti
"""

#This program will generate fibonacci series upto n numbers
#fibonacci series is 1,1,2,3,5,8,13,…

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

print (fibonacci(3))
[/sourcecode]