Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Solution Review: Fibonacci Series

Sumit Rawal answered on May 16, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Exercise: Fibonacci Series

  • Solution Review: Fibonacci Series

    0

    The first thing we need to do is handle all the edge cases. If n is less than 1, we simply have to return -1. If n is 1 or 2, that means we have to return the first or second value in the series.

    Since we already know these are always 0 and 1, we can easily check for them at the start.

    Now begins our while loop. A for loop would work just as well. Our iterator is the count variable, which starts from 3 because we already handled the first two values in the series.

    In every iteration, we use the previous two terms in the sequence, which are second and fib_n. These become first and second in the next iteration.

    In the end, fib_n will hold the final nth value in the Fibonacci sequence.

    Popularity 1/10 Helpfulness 1/10 Language python
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on May 16 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.