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
print("Please enter a positive integer")
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]
# Add remaining terms
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
Recommended Python Programs
- Write a Program to Calculate Simple Interest in Python
- Python Program to Compute Compound Interest
- Leap Year Program in Python
- Python Program to Print Star Pattern
- Number Pattern Programs in Python
- Python Program to Print Even and Odd numbers From 1 to N
- Python Abs() Function: For Absolute Value
- How to Check Whether a Number is Fibonacci or Not in Python
- Python: Program to Find Power of Number
- Python Program to Reverse a Numbers
- Python Program to Find Smallest/Minimum of n Numbers
- Python Program to Find Largest/Maximum of n Numbers
- Python Program to Find The Net Bill Amount After Discount
- Python Program to Print Numbers From N to 1 and 1 to N
- Python Program to Print Numbers Divisible by 3, 5, 7
- Python Program to Print Prime Number 1 to N
- How to Find Square of Number in Python
- Python Program to Calculate Cube of Number
- Python Program to Find LCM of Two Numbers
- BMI (Body Mass Index) Calculator in Python
- Palindrome Program in Python using while loop, Function, etc
- Python: Program to Count Total Number of Bits in Number
- Python Random Number Generator Code
- Zip Zap Zoom Python Program
- Python: program to convert Celsius to Fahrenheit
- Python Program to Swap Two Numbers
- Python Program to Get Standard Deviation
- Python Program to Find the Variance
- Python Program to Convert Height in cm to Feet and Inches
- Python Program to Convert Meters into Yards, Yards into Meters
- Python Program to Convert Kilometers to Meters, Miles
- Python Program to Find Perfect Number
- Python: Program to Find Strong Number
- Python Program Create Basic Calculator
- Python Program For math.floor() Method
- Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
- Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
- Python Program to Find Roots of Quadratic Equation
- Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
- Python Program to Check Given Input is Alphabet, Number or Special Character