views:

91

answers:

4

Possible Duplicate:
How to write the Fibonacci Sequence in Python

Hi. I'm also a learning programmer and I've been asked the same question you were asked for Fibonacci numbers and I can't figure it out. Can you please show me the code you used to generate these numbers asking the user to give numbers and find only the numbers in the range specified? Thank you

A: 

A good google should save the day

http://en.literateprograms.org/Fibonacci_numbers_(Python)

http://stackoverflow.com/questions/494594/how-to-write-the-fibonacci-sequence-in-python

John Smith
that second link looks like a dupe.
Cam
A: 

This question and answers provides you everything you need, I think: http://stackoverflow.com/questions/494594/how-to-write-the-fibonacci-sequence-in-python

Ben Griswold
A: 

I'm not going to give you the code - you should be able to write it yourself. Here are some things you may need to know when writing it however (Not using recursion):

  • Create 3 variables equal to -1 (n1), 1 (n2), and n1 + n2 sumn.
  • Create a loop using for i in range(amount_of_numbers), where amount_of_numbers is how many numbers you want to generate
  • In this loop, reassign n1 to n2, n2 to sumn, and, once again, sumn to n1 + n2.
  • Print out sumn (Inside the loop).

That should be all you need to know if you are really lost on where to go with this. If you need help with specific syntax, you can check out the python docs.

Your output should look like this:

1
1
2
3
5
8
13
21
Zonda333
A: 

fibonacci series for ten numbers,

a,b=0,1
totalno=10
i=0
while i<totalno:
      print a
      a,b=b,a+b
      i+=1
Srinivas Reddy Thatiparthy