猫史档案馆


【Python作品分享】天气预报【作品秀】

用户:一条爱编程的小飞龙一条爱编程的小飞龙查看:0 回复:1 评论:0 创建时间:2022-08-22T18:41:48


【作品展示】

center_image

 

【作品介绍】

输入想预报的城市,可预报今后三天内的天气(温度可能会有小小的误差)

 

【作品源代码】

# -*-coding: utf-8 -*-
import requests
import json

city = input('请输入查询的城市(汉字):')
url = ('http://wthrcdn.etouch.cn/weather_mini?city=' + city)
res = requests.get(url)
data_json = json.loads(res.text)
data = data_json['data']

print('城市:' + data['city'])
print('温馨提示:' + data['ganmao'])
print('温度:' + data['wendu'] + '℃')
print('********************************')
print('昨天日期:' + data['yesterday']['date'])
print('昨天天气:' + data['yesterday']['type'])
print('昨天最高温度:' + data['yesterday']['high'])
print('昨天最低温度:' + data['yesterday']['low'])
print('********************************')
for i in range(0, 3):
    print('日期:' + data['forecast'][i]['date'])
    print('最高温度:' + data['forecast'][i]['high'])
    print('最低温度:' + data['forecast'][i]['low'])
    print('风向:' + data['forecast'][i]['fengxiang'])
    print('--------------------------------')

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
星河非昨夜星河非昨夜

喵喵喵是什么?

 

点赞0


评论