# IndexError: list index out of range

Tue Dec 13 02:47:33 EST 2016

```hi
i am begginer in python. I have written a code and given this error:
IndexError: list index out of range

In my program, I have h=32 bits input. i divide this 32 bits to 4*8 block and every 8-block is n. so n=0:7;(h=int(n/4))
I want to rotate 0 to 7 bits for 2 bits: 0,1,2,3,4,5,6,7--->2,3,4,5,6,7
Iwrite this code:
def rottwo(self, X, n, r):
assert r >= 1
temp = [None]*n
for i in range(n-r) :
temp[i] = X[i+r]
for i in range(n-r,n) :
temp[i] = X[i-n+r]
return temp
this function work correctly. but I also want to rotate 24 to 31 bits for 5 bits: 24,25,26,27,28,29,30,31-->29,30,31,24,25,26,27,28

when I write this code:
def rotfive(self, X, n, r):
assert r >= 1
temp = [None]*n
for i in range(n-r) :
temp[i+24] = X[i+3*n+r]
for i in range(n-r,n) :
temp[i+24] = X[i+2*n+r]
return temp
beacase temp is of size n I cannot access index 3*n+i. index on the list temp should be less than equal to n-1 .
I son't know how I must correct this!!!!!!!!
Is there any one to help me?