該列表應該包含所有januaries和所有februaries等的平均利潤; 我認爲你可以做到這一點的方式是與名單進行比較,比如第一年的名單對janurary,feb,march,...,十二月有價值,從那裏我可以找到基於年份的平均利潤,This一直沒有工作,我不知道該從哪裏出發。有什麼建議麼?比較兩個列表以找到平均值
MONTHS = 12
def average_profit(years):
assert years >= 0, "Years cannot be negative"
total = 0.0
monthly_average = 0.0
total_months = years * MONTHS
total_list = []
average_list=[]
percentage_list = []
for i in range(0, years):
yearly_total = 0.0
for j in range(1, 13):
monthly_profit = float(input("Please enter the profit made in month {0}: ".format(j)).strip())
monthly_average = monthly_average + monthly_profit
month_average = monthly_average/j
total_list.append(monthly_profit)
average_list.append(month_average)
yearly_total = yearly_total + monthly_profit
total_percent = (monthly_profit/12)*100
percentage_list.append(total_percent)
print("Total this year was ${0:.2f}".format(yearly_total))
total = total + yearly_total
average_per_month = total/total_months
return total, average_per_month, total_months, total_list, average_list, percentage_list
好像兩個東西是一樣的..? –