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

Troubles With Learning Modules Python(2) -- Figured out.

In my last post, I had trouble figuring out why the Fibonacci Series wouldn't print. Then suddenly, after spending a bit of time studying and reviewing knowledge that I had acquired, I realized that the issue was in fact the line 6.

# 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 
 
Something as simple as this:
 
 
# 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 
 
That pretty much solved everything for me.
 
Update:  Mon Mar 25 21:47:07

I realized that the issue was with the shell using python 3 instead of python 2. 
Python 2 still uses the print function in the way that I'm used to, python 3 does not.

No comments: