[Tutor] compile problem in emacs

Alan Gauld alan.gauld at blueyonder.co.uk
Sun Feb 22 13:50:35 EST 2004


> this is the code i saved in the emacs ed file ...
> 
> def fib(n):    # write Fibonacci series up to n
> """Print a Fibonacci series up to n."""
> a, b = 0, 1
> while b < n:
> print b,
> a, b = b, a+b


First question, did you really type it like this or did you have 
it indented? I know some mailers strip indentation...?

In Python indentation matters so it should look like:

def fib(n):    # write Fibonacci series up to n
    """Print a Fibonacci series up to n."""
    a, b = 0, 1
    while b < n:
       print b,
       a, b = b, a+b


If you don't have the indentatuion(spacing) as shown Python 
will get confused - and so will your readers! - and throw an error.

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld



More information about the Tutor mailing list