answersLogoWhite

0

A fibonocci sequence is a sequence where each term is equal to the sum of the previous two terms.

1, 1, 2, 3, 5, 8, 13, 21, etc

There are two main ways to do this with Python. The way explained here is through a loop or iteration. The other way would be to use recursion (a function that calls itself).

Note that anything following # is a comment and not part of the code.

Also note that the semicolons are NOT required.

top = raw_input("How high should I go?"); #prompt the user for the stopping point

num1, num2, num3 = 0, 0, 1; #set the num1, num2, and num3 variables equal to 0, 0, and 1 respectively

top = int(top); #top was initially a string variable, this converts it to an integer so we can compare it to our current term

print 1; #print the first 1 in the series

while num3 < top: #execute the indented code while num3 is less than top (our stopping point)

num1 = num2; #set num1 equal to num2 (this is 2 terms ago)

num2 = num3; #set num2 equal to num3 (this is the last term)

num3 = num1 + num2; #calculate the new term for num3

print num3; #display the new term

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Who discovered the fibonocci numbers?

Leonardo Fibonacci


Is python 2.2 a antivirus software?

Python is a programming language, it is used to make computer programs. so you could write an antivirus using python.


What years did Douglas Adams write for Monty Python?

i dont think he was actually a hired writer for monty python. i believe he just helped write with them. check wikipedia.


What is the purpose of print strings in python?

It means that python will print(or write out) a value you input.


How do you write a sequence to a story?

A sequence is just an ordered set of events. You write it by telling what happened in order.


What did Ruskin Bond write in his conceited python?

he was nature lover


How do you write a sequence?

write something, leave a space, write something else.


How do you do sequence?

write something, leave a space, write something else.


Is there anyone that knows a lot about a ball python pls write back FAST?

You mean a Royal python - from it's assigned Latin name of Python regius - Drop me an email through my profile - and I'll answer soon as I get it.


why python is simple?

-It is a high-level and interpreted programming language. -Python is a general-purpose language. -It has a simplified syntax nature. -It is easy to understand. -It is easy to read and write. -Python is much faster than other languages.


How can I generate a random DNA sequence?

To generate a random DNA sequence, you can use a programming language like Python and its random module to create a sequence of random nucleotides (A, T, C, G) of a desired length. This can be achieved by writing a script that randomly selects nucleotides and concatenates them to form the DNA sequence.


What is meant by functions on python?

Python programming allows you to write your own programs. For example, to write a function named double that returns the number that you input, but doubled, we would write the following (where &gt;&gt;&gt;&gt; indicates a tab space) def double(x): &gt;&gt;&gt;&gt;x=x*2 &gt;&gt;&gt;&gt;return x