Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write the Fibonacci Sequence?
    text
    copied!<p>I had originally coded the program wrongly. Instead of returning the Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 should = only those numbers between 1 &amp; 20), I have written for the program to display all Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 displays = First 20 Fibonacci numbers). I thought I had a sure-fire code. I also do not see why this is happening.</p> <pre><code>startNumber = int(raw_input("Enter the start number here ")) endNumber = int(raw_input("Enter the end number here ")) def fib(n): if n &lt; 2: return n return fib(n-2) + fib(n-1) print map(fib, range(startNumber, endNumber)) </code></pre> <p>Someone pointed out in my Part II (which was closed for being a duplicate - <a href="https://stackoverflow.com/questions/504193/how-to-write-the-fibonacci-sequence-in-python-part-ii">https://stackoverflow.com/questions/504193/how-to-write-the-fibonacci-sequence-in-python-part-ii</a>) that I need to pass the startNumber and endNumber through a generator using a while loop. Can someone please point me in the direction on how to do this? Any help is welcome.</p> <hr> <p>I'm a learning programmer and I've run into a bit of a jumble. I am asked to write a program that will compute and display Fibonacci's Sequence by a user inputted start number and end number (ie. startNumber = 20 endNumber = 100 and it will display only the numbers between that range). The trick is to use it inclusively (which I do not know how to do in Python? - I'm assuming this means to use an inclusive range?).</p> <p>What I have so far is no actual coding but rather:</p> <ul> <li>Write Fib sequence formula to infinite</li> <li>Display startNumber to endNumber only from Fib sequence.</li> </ul> <p>I have no idea where to start and I am asking for ideas or insight into how to write this. I also have tried to write the Fib sequence forumla but I get lost on that as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload