2 回答

TA贡献1856条经验 获得超17个赞
这应该工作:
def num3():
with open('sales.txt','w') as fp:
no_days = 7
print('List of Sales in Php')
total = 0
for count in range(1, no_days+1):
sales = float(input('Day' +str(count)+ ':'))
total += sales
total = total
average = total/no_days
fp.write(f'Total Value: {total}\nAverage Value: {average}')
num3()

TA贡献1836条经验 获得超5个赞
您需要将销售额计算在一个单独的变量中。然后除以 no_days:
ifile = open(r'`enter code here`sales.txt', 'w')
no_days = 7
total_sales = 0
for count in range(1, no_days + 1):
print('List of Sales in Php')
sales = float(input('Day' + str(count) + ':\tPhp'))
total_sales += sales
ifile.write(str(sales) + '\n')
ifile.close()
print(f"sum={total_sales}")
print(f"average={total_sales / no_days}")
添加回答
举报