0

次のコードに対して 3 つのことを行う必要があります。

  1. history_ends = 5000 を更新する必要があります

  2. すべての印刷ステートメントをテキスト ファイルに書き込む必要があります

  3. ファイルの行末までこれを行う必要があります

     history_begins = 1; history_ends = 5000; n = 0; total = 0
     historyjobs = []; targetjobs = []
     listsub = []; listrun = []; listavg = [];listfinal = []
    
    def check(inputfile):
      f = open(inputfile,'r')
      lines = f.readlines()
      for line in lines:
        job = line.split()
        if( int(job[0]) < history_ends ):
            historyjobs.append(job)
        else:
            targetjobs.append(job)
      print len(historyjobs)
      print len(targetjobs)
      print targetjobs[0]  
      j = 0           
      for i in range(len(historyjobs)):
         if( (int(historyjobs[i][3]) == int(targetjobs[j][3])) and (int(historyjobs[i][4]) == int(targetjobs[j][4])) and (int(historyjobs[i][5]) == int(targetjobs[j][5])) ):  #i am comparing 3rd,4th & 5th columns of list historyjobs and targetjobs
    
             listsub.append(historyjobs[i][1]) #storing the column num 1 to listsub
    
             listrun.append(historyjobs[i][2]) #storing the column num 1 to listrun
    
      print listsub
      print len(listsub)                
      print listrun 
    
    def runningMean(seq, n=0, total=0):
      if not seq:
        return []
      total =total+int(seq[-1])
      return runningMean(seq[:-1], n=n+1, total=total) + [total/float(n+1)]
    
    def main():
     check('newfileinput')
     listavg = runningMean(listsub,n = 0,total = 0)
     print listavg
     for i in range(len(listsub)):
       if (int(listsub[i]) > float(listavg[i] * 0.9)):
          listfinal.append(listsub[i])
     print listfinal
    
     if __name__ == '__main__':
           main()
    

コードの出力は次のとおりです。

     3756
     215077
     ['5000', '1710390', '930', '8', '9', '2']
     ['767220', '769287', '770167', '770276', '770791', '770835', '771926', '1196500',        '1199789', '1201485', '1206331', '1206467', '1210929', '1213184', '1213204', '1213221', '1361867', '1361921', '1361949', '1364886', '1367224', '1368005', '1368456', '1368982', '1369000', '1370365', '1370434', '1370551', '1371492', '1471407', '1709408', '1710264', '1710308', '1710322', '1710350', '1710365', '1710375']
     37
     ['2717', '184', '188', '163', '476', '715', '1099', '716', '586', '222', '456', '457', '582', '418', '424', '425', '177', '458', '236', '2501', '3625', '1526', '299', '1615', '1632', '1002', '379', '3626', '1003', '1004', '3625', '1002', '1019', '1037', '1066', '998', '977']
     [1282960.6216216215, 1297286.75, 1312372.4571428571, 1328319.6764705882, 1345230.0909090908, 1363181.3125, 1382289.2580645161, 1402634.7, 1409742.7931034483, 1417241.142857143, 1425232.111111111, 1433651.3846153845, 1442738.76, 1452397.5, 1462798.0869565217, 1474143.2727272727, 1486568.142857143, 1492803.2, 1499691.7368421052, 1507344.111111111, 1515724.0, 1525005.25, 1535471.9333333333, 1547401.642857143, 1561126.2307692308, 1577136.75, 1595934.1818181819, 1618484.2, 1646032.3333333333, 1680349.875, 1710198.857142857, 1710330.6666666667, 1710344.0, 1710353.0, 1710363.3333333333, 1710370.0, 1710375.0]
     ['1361867', '1361921', '1361949', '1364886', '1367224', '1709408', '1710264', '1710308', '1710322', '1710350', '1710365', '1710375']

ここで、5001,5002,5003 の結果を表示するための出力が必要です........最後まで & 出力 (print ステートメント) を別のテキスト ファイルに書き込む必要があります。コードは私に結果を提供します.PlzはPythonで解決策を提案できますか

4

1 に答える 1