+ 1

IndexError list out of the range

#this cod is supposed to shif the elements of the #list to right and for the last element to be the first #but I get the error above ::: list=[] n=int(input("type the size of the list: \n")) i=0 while n!=i: list.append(input("type the elemnts: \n")) print (list) i+=1 x=n temp=list[x] while x!=0: list[x]=list[x-1] x-=1 list[0]=temp print(list)

14th Jun 2019, 6:34 PM
Abdullaa Taha
Abdullaa Taha - avatar
2 Réponses
+ 4
temp=list[x-1] while x!=0: list[x-1]=list[x-2] x-=1 List indices are 0 based. A list with n elements doesn't have an element list[n]
14th Jun 2019, 7:08 PM
Anna
Anna - avatar
+ 2
Ohhh thank you
14th Jun 2019, 7:20 PM
Abdullaa Taha
Abdullaa Taha - avatar