# 测试数据
lst_weather = [
["周一", "16℃", "26℃", "多云", "1级", "优"],
["周二", "17℃", "27℃", "晴", "2级", "优"],
["周三", "16℃", "28℃", "晴", "3级", "优"],
["周四", "16℃", "25℃", "阴", "2级", "良"],
["周五", "15℃", "24℃", "阴", "2级", "良"],
["周六", "15℃", "25℃", "晴", "3级", "优"],
["周日", "14℃", "23℃", "小雨", "3级", "良"]
]
# 初始化统计计数器
count_air优 = 0
count_wind_temp = 0
count_avg_temp = 0
# 遍历每天的天气数据
for day in lst_weather:
# 提取当天数据(按索引对应:最低温索引1,最高温2,风力4,空气质量5)
low_temp = int(day[1].replace("℃", "")) # 去掉℃转数字
high_temp = int(day[2].replace("℃", ""))
wind = int(day[4].replace("级", ""))
air = day[5]
# (1)统计空气质量为优的天数
if air == "优":
count_air优 += 1
# (2)统计风力低于3级且最高温≤25℃的天数
if wind < 3 and high_temp <= 25:
count_wind_temp += 1
# (3)统计平均气温低于20℃的天数
avg_temp = (low_temp + high_temp) / 2
if avg_temp < 20:
count_avg_temp += 1
# 输出结果
print("空气质量为优的天数:", count_air优)
print("风力低于3级且最高气温不超过25℃的天数:", count_wind_temp)
print("平均气温低于20℃的天数:", count_avg_temp)