Just A Small Guideline

Feel free to browse the site. Don't be afraid to leave comments, they're supportive.
Please follow me on Twitter @ehldmnt and retweet my posts.

Sunday, March 24, 2013

Trouble with Learning Modules in Python (2)

So, I was reading directly from the python Documentation, and on this page they present a code that actually creates the Fibonacci series:

# Fibonacci numbers module

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

def fib2(n): # return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result
 
 
This code has worked before, but this is the first time I've ever run into problems with it on the python
 interpreter.
I've actually typed it in manually at first, and then attempted to utilize this code, and got this error:
 
[python_prac_mod]> python 
Python 3.3.0 (default, Dec 22 2012, 21:02:07) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import fibo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "./fibo.py", line 6
    print b,
          ^
SyntaxError: invalid syntax
>>> 

Strange as hell. I even tried copy pasting the python code into the file and then saving it. 
That didn't work either. And despite my limited knowledge of python programming, I feel that this error is not
quite accurate. Oh, well, I'll have to look up another tutorial or something.

No comments: