Q:

Creating fibonacci sequence generator (Beginner Python)

Hi I'm trying to create a Fibonacci sequence generator in Python. This is my code:
d =raw_input("How many numbers would you like to display")

a = 1
b = 1

print a
print b

for d in range(d):
    c = a + b 
    print c
    a = b
    b = c

When I ran this program, I get the error:
File "Fibonacci Sequence Gen.py", line 10, in <module>
    for d in range(d):
TypeError: range() integer end argument expected, got str

Thanks for your help, I'm trying to teach myself python with basic projects. 

A:

raw_input returns a string. So convert d to an integer with:
d = int(d)

One more thing: Do not use for d in range(d). It works but it is awful, unpythonic, whatever.
Try this way for example:
numbers = raw_input("How many numbers would you like to display")

a = 1
b = 1

print a
print b

for d in range(int(numbers)):
    c = a + b 
    print c
    a = b
    b = c

Edit: I complete below the answer with additional code tuning (thanks to commenters):
# one space will separate better visually question and entry in console
numbers = raw_input("How many numbers would you like to display > ")    

# I personnally prefer this here, although you could put it
# as above as `range(int(numbers))` or in `int(raw_input())`
# In a robust program you should use try/except to catch wrong entries
# Note the number you enter should be > 2: you print 0,1 by default
numbers = int(numbers)  

a, b = 0, 1        # tuple assignation
                   # note fibonnaci is 0,1,1,2,3...

print a            # you can write this as print "%i\n%i" % (a, b)
print b            # but I think several prints look better in this particular case.

for d in range(numbers - 2):  # you already printed 2 numbers, now print 2 less
    c = a + b 
    print c
    a, b = b, c    # value swapping.
                   # A sorter alternative for this three lines would be:
                   # `a, b = b, a + b`
                   # `print b` 

A:

Problem
The problem here is that here:
d = raw_input("How many numbers would you like to display")

you assign string from the input into the d variable, and later you pass it to range(). But range() expects expects integers, not strings, and Python does not convert it automatically (it leaves conversion to you).
Solution
The solution is to convert result of raw_input() into int like that:
d = int(raw_input("How many numbers would you like to display"))

and everything will work unless you provide non-integer.
But there is better (shorter, more efficient, more encapsulated) method of generating Fibonacci numbers (see below).
Better method of generating Fibonacci numbers
I believe this is the best (or nearly 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 does not print anything, but you can print its result like that:
>>> 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 into a list like that:
>>> list(fibo(20))
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]

Applying the above in your case
After applying the above to your code, it could 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 it answer your question?

A:

You have to convert the input to a number, like this:
d = int(raw_input("How many numbers would you like to display: "))

Also, just for fun, the fibonacci sequence can be expressed more succinctly:
a, b = 0, 1
for i in range(d):
    print a
    a, b = b, a+b

