Python Forum

Full Version: List Indices must be Integers?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to plot a list of the the outputs as a list with the corresponding time values, for this function with a varied number of iterations. I'm not sure why I keep getting "List Indices must be Integers" however. Was wondering if anyone could look at my code and see what's wrong and how I might fix it.

 

def iterate3(finaltime2,stepsize):
    g(x) = 10*e^(0.05*x)
    count = srange(0,finaltime2/stepsize)
    initialvalat0 = [10]
    for i in count:
        a = g(initialvalat0[i])
        initialvalat0.append(a)
    return zip(srange(0,finaltime2/stepsize),initialvalat0)

graph4 = iterate3(10,0.1)
graph5 = iterate3(100,0.1)
graph6 = iterate3(100,0.01)

list_plot(graph4)
You need to provide: (1) the stacktrace for your problem and (2) the full code that produces that stacktrace.
Ideally you provide a minimal amount of code for the problem you're having (5-10 lines, rather than your full project), but (1) and (2) are essential to us providing help.