0

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

Community
  • 1
  • 1

3 Answers3

1

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
John Howard
  • 55,887
  • 22
  • 47
  • 65
0

A good google should save the day

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

How to write the Fibonacci Sequence in Python

Community
  • 1
  • 1
John Smith
  • 11,997
  • 16
  • 62
  • 109
0

This question and answers provides you everything you need, I think: How to write the Fibonacci Sequence in Python

Community
  • 1
  • 1
Ben Griswold
  • 17,253
  • 14
  • 55
  • 60