我是編程新手,我試圖找到百分比最高的日子。出於某種原因,我的輸出作爲最高比例持續到第2週三。下面是輸出我想獲得:在python中找不到最大值
以下是其他列表中主
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("***************************************")
從「percent =(defects [index]/pieces [index])」計算得出的值將始終爲零,因爲它是整數計算。 –