Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8124399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:27:01+00:00 2026-06-06T06:27:01+00:00

I have problem understanding what the return fibonacci( number-1 ) + fibonacci( number-2 )

  • 0

I have problem understanding what the return fibonacci( number-1 ) + fibonacci( number-2 ) does in the following program:

import sys
def fibonacci( number ):
    if( number <= 2  ):
        return 1
    else:
        return fibonacci( number-1 ) + fibonacci( number-2 )

The problem is that I can’t imagine how this line works:

return fibonacci( number-1 ) + fibonacci( number-2 )

Does the both of the “fibonacci( number-1 )” and “fibonacci( number-2 )” being processed at the same time? or the “fibonacci( number-1 )” is the first to be processed and then the second one?

I only see that processing both of them would eventually return ‘1’ so the last result I expect to see it is a ‘1 + 1’ = ‘2’

I would appreciate a lot, If someone can elaborately explain the process of its calculation.

I think this is a very newb question but I can’t really get a picture of its process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:27:03+00:00Added an answer on June 6, 2026 at 6:27 am

    Why don’t you do something like this:

    >>> def fibonacci(number):
    ...     if number < 2:
    ...         return number
    ...     print "Number is currently %d, getting fibonacci(%d)" % (number, number - 1)
    ...     minus_one = fibonacci(number-1)
    ...     print "Number is currently %d, just got fibonacci(%d), now getting fibonacci(%d)" % (number, number - 1, number - 2)
    ...     minus_two = fibonacci(number-2)
    ...     print "Number is currently %d, returning %d + %d" % (number, minus_one, minus_two)
    ...     return minus_one + minus_two
    

    So that when you call fibonacci you get something like this:

    >>> fibonacci(4)
    Number is currently 4, getting fibonacci(3)
    Number is currently 3, getting fibonacci(2)
    Number is currently 2, getting fibonacci(1)
    Number is currently 2, just got fibonacci(1), now getting fibonacci(0)
    Number is currently 2, returning 1 + 0
    Number is currently 3, just got fibonacci(2), now getting fibonacci(1)
    Number is currently 3, returning 1 + 1
    Number is currently 4, just got fibonacci(3), now getting fibonacci(2)
    Number is currently 2, getting fibonacci(1)
    Number is currently 2, just got fibonacci(1), now getting fibonacci(0)
    Number is currently 2, returning 1 + 0
    Number is currently 4, returning 2 + 1
    3
    

    It’s still complex, but at least now you can see what the function is doing to calculate your number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an understanding problem of how the following code works: XMLInputFactory xif =
Hello all I have a problem with understanding the bitsort program in Bentley's classic
I have a homework problem where I have to make an inheritance program that
I have some problem in understanding how does the asp.net mvc deal with Null
hello everyone I have some problem with understanding this piece of the code: import
I have the following basic (and maybe stupid) understanding problem in JSF: There is
I have a problem in understanding the LINQ to Entites query which does not
I seem to have a problem understanding how to conditionally test a boolean value
I think I have a problem in understanding the proper way of using MVC.
I think i have a basic problem in understanding the dojo toolkit. Well I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.