Screen Link:
My Code:
values = [72, 48, 7, 66, 62, 32, 33, 75, 30, 85, 6, 85, 82, 88, 30, 32, 78, 39, 57, 96, 45, 57, 61, 10, 62, 48, 32, 96, 75, 15]
for i in range(len(values)):
if values[i] < values[i+1]:
maximum = values[i+1]
print(maximum)
What I expected to happen:
It returns the desired answer for variable maximum, but how do I remedy the error using a while statement?
Replace this line with the output/error
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-1-45c7bb6309e2> in <module>
2
3 for i in range(len(values)):
----> 4 if values[i] < values[i+1]:
5 maximum = values[i+1]
6 print(maximum)
IndexError: list index out of range
The error occurs, but if i return maximum, i get the correct value. How do i remove that error using a while condition? I understand that if python iterates through the last index, the i+1 > the last index of the values list.