Question: How do I make this section of my code a loop? Mile1 = inbetween(MPT,15,16) Mile2 = inbetween(MPT,16,17) Mile3 = inbetween(MPT,17,18) Mile4 = inbetween(MPT,18,19) Mile5 =
How do I make this section of my code a loop?
Mile1 = inbetween(MPT,15,16)
Mile2 = inbetween(MPT,16,17)
Mile3 = inbetween(MPT,17,18)
Mile4 = inbetween(MPT,18,19)
Mile5 = inbetween(MPT,19,20)
Mile6 = inbetween(MPT,20,21)
Mile7 = inbetween(MPT,21,22)
Mile8 = inbetween(MPT,22,23)
Here is the entire code:
import numpy as np import pandas as pd import matplotlib.pyplot as plt
def inbetween(MPT,a=15,b=23): count = 0 for eachMPT in MPT: if eachMPT >= a and eachMPT < b: count = count + 1 return count
pinfo = pd.read_excel("Project-02-crash-data-set.xlsx") ptranspose = pinfo.transpose() ainfo = ptranspose.to_numpy() print(ainfo)
MPT = ainfo[5] LC = ainfo[9] RC = ainfo[10]
print(MPT) print(LC) print(RC)
Mile1 = inbetween(MPT,15,16) Mile2 = inbetween(MPT,16,17) Mile3 = inbetween(MPT,17,18) Mile4 = inbetween(MPT,18,19) Mile5 = inbetween(MPT,19,20) Mile6 = inbetween(MPT,20,21) Mile7 = inbetween(MPT,21,22) Mile8 = inbetween(MPT,22,23)
print(Mile1) print(Mile2) print(Mile3) print(Mile4) print(Mile5) print(Mile6) print(Mile7) print(Mile8)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
