A community for students.
Here's the question you clicked on:
 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
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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0This is the one i couldn't understand. Can you explain to me the idea please. Thanks

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0A 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I can't understand old_a and old_b issues

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Those 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sammi789 is a spammer and i would bet her website doesn't specifically cater to the MIT OCW class like this one does.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0a = 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...
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.