Fibonacci Series – Python

# -*- 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))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.