Q:

for-loops in Python modules

I'm writing a function for an implicit scheme for solving a specific differential equation. The function looks like this:
import numpy as np

def scheme(N,T):
    y = np.zeros(N+1)          # Array for implicit scheme
    h = T/N                    # Step length
    for i in range(N):
        y[i+1] = y[i] + h*(1+4*y[i])

    print y

I save the file and later import it the usual way, but when I run the scheme function, y = [0 ... 0] where ... are N-1 zeros. It seems like the values are lost in the scope of the for-loop.
If I instead write the whole function in the interpreter (which in my case is Spyder), everything works as it should.
Why doesn't it work when importing the function from the module?

A:

h = T/N 

is it possible that T and N are both integers and T < N? In that case h = 0 (and y stays all zeros), because it is an integer division (1/2 == 0).
Try to replace this line with 
h = 1. * T / N 

and see the results.
y[i+1] = y[i] + h*(1+4*y[i])

can be rewritten as
y[i+1] = y[i] + h + 4 * h * y[i]
               ^^^

which means that for y[i] = 0, the new y[i+1] will be h. If the integer division T/N makes it zero, then it is what you get.

