No imports allowed. I am writing a program for a simple moving average but keep getting an error.
inp = 12345
lst = [int(x) for x in str(inp)]
x = range (len(lst))
for n in x:
An =((lst[n]+ lst[n+1])/2)
print(An)
n+=1
I keep getting:
1.5
2.5
3.5
4.5
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-16-ea7ffe0bd993> in <module>
4 for n in x:
5 while n <= 5:
----> 6 An =((lst[n]+ lst[n+1])/2)
7 print(An)
8 n+=1
IndexError: list index out of range
I know it is because of the last[n+1]
term but no matter what while
conditions I have tried I cannot get around this simple error