Python Forum
Is this right/ what should i change?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is this right/ what should i change?
#5
pour_list = [1,2,5,6,3,77,9,0,3,23,0.4,-12.4,-3.12]

for i in range(0, len(our_list), 2):
left = our_list[i]
right = our_list[i+1]
print("{0} - {1} = {2}".format(left, right, (left-right)))
1 - 2 = -1
5 - 6 = -1
3 - 77 = -74
9 - 0 = 9
3 - 23 = -20
0.4 - -12.4 = 12.8
Traceback (most recent call last):

File "<ipython-input-5-3f1c5e913d44>", line 5, in <module>
right = our_list[i+1]

IndexError: list index out of range



why does it keep saying list index out of range?
Reply


Messages In This Thread
Is this right/ what should i change? - by ralfi - Sep-20-2017, 06:12 PM
RE: Is this right/ what should i change? - by ralfi - Sep-20-2017, 07:18 PM
Index out of range - by ralfi - Sep-22-2017, 08:11 PM
RE: Index out of range - by snippsat - Sep-22-2017, 08:28 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020