猫史档案馆


【Python作品分享】城市查询

用户:VerymanVeryman查看:0 回复:1 评论:0 创建时间:2022-02-01T14:59:37


【作品展示】

center_image

 

【作品介绍】

例:北京

 

【作品源代码】

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

print('此功能可以查询中国的城市')
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下一页
VerymanVeryman

发布者(veryman):'喵喵喵'替换为' http://wthrcdn.etouch.cn/weather_mini?city='未经作者允许禁止转载

点赞0


评论