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
   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

  1. Write a Program to Calculate Simple Interest in Python
  2. Python Program to Compute Compound Interest
  3. Leap Year Program in Python
  4. Python Program to Print Star Pattern
  5. Number Pattern Programs in Python
  6. Python Program to Print Even and Odd numbers From 1 to N
  7. Python Abs() Function: For Absolute Value
  8. How to Check Whether a Number is Fibonacci or Not in Python
  9. Python: Program to Find Power of Number
  10. Python Program to Reverse a Numbers
  11. Python Program to Find Smallest/Minimum of n Numbers
  12. Python Program to Find Largest/Maximum of n Numbers
  13. Python Program to Find The Net Bill Amount After Discount
  14. Python Program to Print Numbers From N to 1 and 1 to N
  15. Python Program to Print Numbers Divisible by 3, 5, 7
  16. Python Program to Print Prime Number 1 to N
  17. How to Find Square of Number in Python
  18. Python Program to Calculate Cube of Number
  19. Python Program to Find LCM of Two Numbers
  20. BMI (Body Mass Index) Calculator in Python
  21. Palindrome Program in Python using while loop, Function, etc
  22. Python: Program to Count Total Number of Bits in Number
  23. Python Random Number Generator Code
  24. Zip Zap Zoom Python Program
  25. Python: program to convert Celsius to Fahrenheit
  26. Python Program to Swap Two Numbers
  27. Python Program to Get Standard Deviation
  28. Python Program to Find the Variance
  29. Python Program to Convert Height in cm to Feet and Inches
  30. Python Program to Convert Meters into Yards, Yards into Meters
  31. Python Program to Convert Kilometers to Meters, Miles
  32. Python Program to Find Perfect Number
  33. Python: Program to Find Strong Number
  34. Python Program Create Basic Calculator
  35. Python Program For math.floor() Method
  36. Python Program to Find Sum of Series 1/1! 2/2! 3/3! …1/n!
  37. Python: Program to Convert Decimal to Binary, Octal and Hexadecimal
  38. Python Program to Find Roots of Quadratic Equation
  39. Python Program to Print Alphabets from A to Z in Uppercase and Lowercase
  40. Python Program to Check Given Input is Alphabet, Number or Special Character

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *