【发布时间】:2021-05-21 08:58:46
【问题描述】:
所以,我有这个file.txt,还要做每天的平均气温,file.txt要大很多,所以有很多天
data : 2021-05-01 16:52:13.074093
Temperature: 25.20 C
Pressure: 986.57 hPa
Altitude: 224.50
data : 2021-05-01 16:52:18.129364
Temperature: 25.20 C
Pressure: 986.55 hPa
Altitude: 224.61
我做了平均,但我不知道每天如何做 这是到目前为止的代码
def temperature():
print("The average temperature is:")
total = 0.0
c = 0
with open("text.txt", 'r') as f:
for line in f:
if "Temperature" not in line: continue
temp = line.split(" ")[1]
total =total+ float(temp)
c =c+ 1
print(total / c)
【问题讨论】:
标签: python python-3.x average