This question has already been answered:
The program must, for each element of this list, print the sum of its two neighbors. For list items that are extreme, one of the neighbors is considered to be an item located at the opposite end of this list. For example, if the input is a list of "1 3 5 6 10", then the output is expected to list "13 6 9 15 7" (without quotes). If only one number has come to the input, you must output it. The output should contain one line with the numbers of the new list, separated by a space.
count=[] nums=input() row = list(map(int, nums.split())) i=0 while i<=len(row): if len(row) == 1: print(row[0]) if i == 0: count.append(row[-1] + row[1]) if i == len(row): count.append(row[-2] + row[0]) if 0<i<len(row): count.append(row[i-1] + row[i+1]) i+=1 print(count) I can not understand why it gives an error about exceeding the boundaries. There is a similar question here, but I can not figure out the answers.