2017-04-30 8 views
-2

私はプログラミングが初めてで、最高のパーセンテージでその日を探しています。何らかの理由で、私のアウトプットは、週2の水曜日が最高のパーセンテージとして出てきています。ここで私が取得しようとしています出力されます。Pythonで最大値を見つけるのに問題があります

ここでは、他のリストはmax(list1)へのあなたの呼び出しは、この問題を引き起こしている主な

pieces = [10, 14, 15, 12, 20, 18, 17, 9, 23, 21, 20, 16, 17, 22] defects = [ 3, 5, 7, 8, 9, 2, 5, 2, 7, 4, 8, 5, 6, 9]

list1, percentlist = ['Wk 1 Monday', 'Wk 1 Tuesday', 'Wk 1 Wednesday', 'Wk 1 Thursday', 'Wk 1 Friday', 'Wk 1 Saturday', 'Wk 1 Sunday', 'Wk 2 Monday', 'Wk 2 Tuesday', 'Wk 2 Wednesday', 'Wk 2 Thursday', 'Wk 2 Friday', 'Wk 2 Saturday', 'Wk 2 Sunday'] ,[]

for index in range(0, len(pieces)): 
    percent = (defects[index]/pieces[index]) 
    percentlist.append(percent * 100)   
print("***************************************") 
print("The highest percent of defects per piece: ", 
format(max(percentlist),'.2f'),'%') 
print("Occured on: \t\t\t", max(list1)) 
print("***************************************") 
+0

"percent =(defects [index]/pieces [index])"から計算されたprecentは、整数計算であるため、常にゼロになります。 –

答えて

0

です。

インデックスに最大値に対応するインデックスをpercentlistにするようにプログラムに指示する必要があります。

index = percentlist.index(max(percentlist)) # add this line 
print("Occured on: \t\t\t", list1[index]) # modify your existing line 
関連する問題