Problem
The problem here is that here:
d = raw_input("How many numbers would you like to display")
you assign a string from input to variable d , and then pass it to range() . But range() expects integers, not strings, and Python doesn't convert them automatically (it leaves the conversion for you).
Decision
The solution is to convert the result of raw_input() to int as follows:
d = int(raw_input("How many numbers would you like to display"))
and everything will work if you do not provide an integer.
But there is a better (shorter, more efficient, more encapsulated) method of generating Fibonacci numbers (see below).
The best way to generate Fibonacci numbers
I believe this is the best (or almost the best) solution:
def fibo(n): a, b = 0, 1 for i in xrange(n): yield a a, b = b, a + b
This is a generator, not a simple function. It is very efficient, its code is short and doesn't print anything, but you can print its result as follows:
>>> for i in fibo(20): print i, 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
or convert it to a list:
>>> list(fibo(20)) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
The application of the above in your case
After applying the above code, it may look like this:
def fibo(n): a, b = 0, 1 for i in xrange(n): yield a a, b = b, a + b d = int(raw_input("How many numbers would you like to display")) for i in fibo(d): print i
Does your question answer your question?