I'm having trouble with my loops. I get an error for 400 being out of range. Am I applying something that is not allowed, or what is my issue? It looks like legal syntax to me?
survTime=np.array([400, 800, 1100, 900])
age=np.array([40, 40, 40, 40])
counter_1yr=0
counter_2yr=0
counter_3yr=0
n=1
for i in survTime:
for j in age:
if survTime[i] > 365 and age[j] < 50:
counter_1yr+=1
n+=1
continue
elif survTime[i] > 730 and age[j] < 50:
counter_2yr+=1
n+=1
continue
elif survTime[i] > 1095 and age[j] < 50:
counter_3yr+=1
n+=1
continue
print("1 year probability: ", counter_1yr/n)
print("2 year probability: ", counter_2yr/n)
print("3 year probability: ", counter_3yr/n)
for i in survTimedoes not give you a counter from0 -> len(survTime)it gives you the actual values of survTime one by one. You do not need to access the arrays by index after that. The way you are doing it, one the first loop will yield the callif survTime[400] > 365 and age[40] < 50:- which is clearly out of range. You can just do ifi > 365 and j < 50: