How do I create a module for a fibonacci sequence in Python on a Mac with TextWrangler?
Question: I've been trying to search up valid sequences online but haven't come across
one that works in Python interpreter. Every time I input a sequence, the
interpreter always finds some sort of mistake or is not able to formulate a
module specific to it that I can import. Along with that, I have not been able
to find a downloadable version of the module for Mac.

I've used several sequences. Maybe there are numbers I must input in addition
to it? I've been using this sequences in raw form, copying and pasting from a
website to TextWrangler:

    
    
    # Fibonacci numbers module
    
    def fib(n):    # write Fibonacci series up to n
        a, b = 0, 1
        while b < n:
            print(b, end=' ')
            a, b = b, a+b
        print()
    
    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
    

I am trying to use an importable version in order to solve Project Euler's
problem number 2. I'm a beginner and interested in learning more about
programming in order to pursue computational sciences.


Answer: Put this in a file named `fibonacci.py`:

    
    
    def fib(n):    # write Fibonacci series up to n
        a, b = 0, 1
        while b < n:
            print(b, end=' ')
            a, b = b, a+b
        print()
    
    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
    

Then open an other file `__main__.py` in the same folder as `fibonacci.py`.
The content of `__main__.py` should be:

    
    
    import fibonacci
    print(fibonacci.fib(3))
    

Then you can execute the `__main__.py` file and it should work.

