用python做一个程序,能够存储数据并输出平均值
发布网友
发布时间:2023-11-09 19:07
我来回答
共2个回答
热心网友
时间:2024-12-13 23:37
这么简单实现行吗
sum = 0.0
count = 0
with open('numbers.txt', 'a') as f:
while True:
value = input('Input number:')
if value == '':
break
sum = sum + float(value)
count += 1
f.write(value + '\n')
f.write('avg= ' + str(sum / count) + '\n')
print('avg= ' + str(sum / count) + '\n')
热心网友
时间:2024-12-13 23:37
a=(2,2,4,5,6,7,3.0, 5.5)
avg = sum(a) / len(a)
print avg