python - List Index Out of Range Error - cannot get code to run -


question all. i'm coding assignment school in have simulate physical process of water flowing between 3 ponds, , how pollutant dumped pond 1 flows between ponds. keep getting error "indexerror: list index out of range". have tinkered around different things day cannot error go away.

here code below: (fyi python says have error on line 49, 32, , 38).

pond_1 = [0] pond_2 = [0] pond_3 = [0]  # pond 1 def pond1(timeinput):     pollutants = inflow3(timeinput-1)-outflow2(timeinput-1)+pond_1[timeinput-1]     total = leakinginput*timeinput     if total <= maximuminput:         pollutants += leakinginput     return pollutants  def inflow3(timeinput):     return 0.005*pond_3[timeinput]  def outflow2(timeinput):     return 0.005*pond_1[timeinput]  #pond 2 def pond2(timeinput):     return inflow1(timeinput-1)-outflow3(timeinput-1)+pond_2[timeinput-1]  def inflow1(timeinput):     return 0.005*pond_1[timeinput]  def outflow3(timeinput):     return 0.005*pond_2[timeinput]  #pond 3 def pond3(timeinput):     return inflow2(timeinput-1)-outflow1(timeinput-1)+pond_3[timeinput-1]  def inflow2(timeinput):     return 0.005*pond_2[timeinput]  def outflow1(timeunput):     return 0.005*pond_3[timeinput]  # user input maximuminput = int(input("please enter maximum amount of pollutant: ")) leakinginput = float(input("please enter rate in pollutant leaking: ")) timeinput = int(input("please enter amount of time simulation run in minutes: "))  # amount of pollutant in pond every hour calculation n in range(0, timeinput+1):     pond_1.append(pond1(n))     pond_2.append(pond2(n))     pond_3.append(pond3(n))      if n % 60 == 0:         print("the amount of pollutant in pond 1 is: ", pond_1[n])         print("the amount of pollutant in pond 2 is: ", pond_2[n])         print("the amount of pollutant in pond 3 is: ", pond_3[n])      if n == timeinput:         print("final number of pollutants in pond 1", pond_1[timeinput])         print("final number of pollutants in pond 2", pond_2[timeinput])         print("final number of pollutants in pond 3", pond_3[timeinput]) 

it's typo:

def outflow1(timeunput): 

has be:

def outflow1(timeinput): 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -