A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

fibonacci sequence....i found this code and it really worked but i don't understand how code was excuted. Thank

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    1 Attachment
  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I couldn't open your attachments, but there is an example on this page of how to calculate Fibonacci sequences: http://en.wikibooks.org/wiki/Python_Programming/Loops

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    This is the one i couldn't understand. Can you explain to me the idea please. Thanks

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    A Fibonnaci sequence is where a number is the sum of the previous two numbers in the sequence (the sequence begins 0, 1). This code gives the first 20 Fibonnaci numbers. So each number is the sum of the previous two. The last three numbers are 1597 2584 4181. 1597 + 2584 = 4181

  6. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I can't understand old_a and old_b issues

  7. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Those are variables that allow you to keep track of the previous two numbers in the sequence. Try printing out the code and writing in the values as you go along.

  8. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    sammi789 is a spammer and i would bet her website doesn't specifically cater to the MIT OCW class like this one does.

  9. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    a = 0 b = 1 count = 0 max_count = 20 while count < max_count: count = count + 1 #we need to keep track of a since we change it old_a = a old_b = b a = old_b b = old_a + old_b #Notice that the , at the end of a print statement keeps it # from switching to a new line print (old_a,) print() so this is the code u worked out right note that Fibonacci number is sum of previous two numbers in the sequence.. ex: if 0,1 are the first two numbers in sequence then the next fibonacci number will be 1(i.e..0+1) so by the above code here two numbers in the sequence are initialized i.e a=0,b=1 here this code prints 20 numbers in fibonacci sequence.. so max_count is initialized as 20. in order to print from beginning a while loop is used. and it is incremented to print next numbers.. old_a,old_b are used to swap these numbers.. U JUST TRY THE COMPUTER EXECUTION ON A PAPER then u can understand how this code is working...

  10. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.