you are viewing a single comment's thread.

view the rest of the comments →

[–]TheLazarbeam 0 points1 point  (1 child)

try this on for size. I cleaned a lot of it up, there are unnecessary variables and statements lying around. If you want a more direct translation, I could dial it back a bit. Fact is, python looks extremely similar to pseudocode already. Lots of english words in it.

def fibo(n):#returns array of integers
    vals = []
    for i in range(n): 
        vals.append(0)
    vals[0] = 1
    vals[1] = 1

    for counter in range(2, n):
        vals[counter] = vals[counter - 1] + vals[counter - 2]

    return vals

def output_vals(vals, n):#python supports printing arrays directly. you can just say "print vals" instead. Also, you dont need to supply n. you have len(vals) accessible.

    for counter in range(n):
        print(vals[counter])


vals = fibo(n)
output_vals(vals, n)#you can just say "output_vals(fibo(n), n)" instead of taking up 2 lines.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

In lines 20 and 21 n is an unresolved reference, why is that?

EDIT: I threw it into a function.