So I've gotten mostly everything to work for my python project except for this. I keep getting this error
builtins.IndexError: list index out of range
for line 10 which is asterixed to show the location of the problem.
i = 0
**NumberOfHorses=int(sys.argv[1])**
while i!=NumberOfHorses:
and I'm not sure how to fix it or what is wrong. Any help? Here is the full code.
from random import randint
import sys
horse = {}
randNumber={}
timeTaken={}
currentPosition={}
totalTime = {}
i = 0
NumberOfHorses=int(sys.argv[1])
while i!=NumberOfHorses:
horse[i]=0
timeTaken[i]=0
currentPosition[i]=0
i+=1
check=0
i=0
totalMiles = 10560
while(1):
for i in range(0,NumberOfHorses):
currentPosition[i] = currentPosition[i] + randint(4,41)
if(currentPosition[i]>= 10560):
check=1
break
timeTaken[i]+=1
if(check==1):
break
print ('race is finished with following details:')
for i in range(0,NumberOfHorses):
print ('horse no.',i, 'distance covered-',currentPosition[i],'in time ',timeTaken[i])
Thanks in advance.