# Python Program to Find nth term of a Fibonacci Series

Program to find nth fibonacci number in python; In this tutorial, you will learn how to find nth term in fibonacci series in python using for loop, while loop and recursion function.

## Python Program to Find nth term of a Fibonacci Series

• Fibonacci series in python using for loop
• Fibonacci series python programming using while loop
• Fibonacci series in python using recursion
• Sum of fibonacci series in python

### Fibonacci series in python using for loop

# Take input from user
a=int(input("Enter the terms"))
f=0
s=1
if a<=0:
print("The requested series is ",f)
else:
print(f,s,end=" ")
for x in range(2,a):
next=f+s
print(next,end=" ")
f=s
s=next

Output

Enter the terms 15
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

### Fibonacci series python programming using while loop

# Python Fibonacci series Program using While Loop

# Fibonacci series will start at 0 and travel upto below number
Number = int(input("\nPlease Enter the Range Number: "))

# Initializing First and Second Values of a Series
i = 0
First_Value = 0
Second_Value = 1

# Find & Displaying Fibonacci series
while(i < Number):
if(i <= 1):
Next = i
else:
Next = First_Value + Second_Value
First_Value = Second_Value
Second_Value = Next
print(Next)
i = i + 1

Output

Please Enter the Range Number:  10
0
1
1
2
3
5
8
13
21
34

### Fibonacci series in python using recursion

def FibRecursion(n):
if n <= 1:
return n
else:
return(FibRecursion(n-1) + FibRecursion(n-2))
nterms = int(input("Enter the terms? "))  # take input from the user

if nterms <= 0:  # check if the number is valid
else:
print("Fibonacci sequence:")
for i in range(nterms):
print(FibRecursion(i))

Output

Enter the terms?  15
Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377

### Sum of fibonacci series in python

# Python to calculate sum of Fibonacci numbers

# Computes value of first
# fibonacci numbers
def calSum(n) :
if (n <= 0) :
return 0

fibo =[0] * (n+1)
fibo[1] = 1

# Initialize result
sm = fibo[0] + fibo[1]

for i in range(2,n+1) :
fibo[i] = fibo[i-1] + fibo[i-2]
sm = sm + fibo[i]

return sm

#take input from user
n=int(input("Enter the terms"))

#call calSum() function and print result
print("Sum of Fibonacci numbers is : " ,
calSum(n))

Output

Enter the terms 10
Sum of Fibonacci numbers is :  143