pro = pro*(x[ip] - x[ir]) giving tuple index out of range error new to python
Question: This is the code and please help I'm getting **tuple index out of range
error** in line 19

    
    
    import math
    n = 7
    x = 0.5,1.2,2.1,2.9,3.6,4.5,5.7
    y = 3.2,5.2,9.3,14.6,20.5,30.1,45.2
    xx = 3.4
    yy = y[0 ]
    fact = 1
    for i in range(0,n):
        fact = fact*(xx - x[i])
        s = 0.0
        i1 = i+ 2
        for ip in range(0,i1):
            pro = 1.0
            for ir in range(0,i1):
                if (ir == ip): continue
                pro = pro*(x[ip] - x[ir])
            s = s + y[ip]/pro
        yy = yy + s*fact
    print "x=%5.2f      y=%5.2f"  %(xx,yy)
    


Answer: You're setting `i1 = i + 2` in your loop. Since i runs from 0 to n, i1 is set
to values larger than the length of `x`. If you put a

    
    
    print i1
    

before the `for ip`, you can see exactly where it goes wrong.

