Python Program to Find Fibonacci Series up to Nth Term

    The Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. The simplest form of the Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, etc.

    The series was named after Leonardo Fibonacci, an Italian mathematician who introduced it in his book Liber Abaci in 1202.

    The Fibonacci series has many applications in mathematics, particularly in the field of combinatorics. It also appears in nature in the spiral arrangement of leaves, seeds, and petals.

    The Fibonacci series is generated by starting with 0 and 1 and then adding the two previous numbers to get the next number in the series.

    Program Code

    def fibonacci(n):
        a = 0
        b = 1
        if n == 1:
            for i in range(2,n):
                c = a + b
                a = b
                b = c
    n = int(input("Enter the value of 'n': "))

    Input Given:

    Enter the value of 'n': 9

    Expected Output:


    Code Explanation

    1. First, we take the number of terms from the user.
    2. Then we initialize the first two terms of the series to 0 and 1.
    3. Next, we use a for loop to iterate from 2 to the number entered by the user.
    4. In the loop, we add the previous two terms to get the next term.
    5. We then update the first and second terms to be the second and third terms, respectively.
    6. Finally, we print the series.
    Disclaimer: While we make every effort to update the information, products, and services on our website and related platforms/websites, inadvertent inaccuracies, typographical errors, or delays in updating the information may occur. The material provided on this site and associated web pages is for reference and general information purposes only. In case of any inconsistencies between the information provided on this site and the respective product/service document, the details mentioned in the product/service document shall prevail. Subscribers and users are advised to seek professional advice before acting on the information contained herein. It is recommended that users make an informed decision regarding any product or service after reviewing the relevant product/service document and applicable terms and conditions. If any inconsistencies are observed, please reach out to us.

    Latest Articles

    Related Stories

    Leave A Reply

    Please enter your comment!
    Please enter your name here

    Join our newsletter and stay updated!