+ 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)
2 Respostas
+ 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]
+ 2
Ohhh thank you