江西省建设协会网站,网上推广什么比较赚钱,门户网站 管理系统,网页设计尺寸要求刚入门python#xff0c;借鉴了论坛上前人写的天气查询程序通过使用中国天气网的API接口来实现如图#xff1a;贴上源代码#xff0c;希望大家评论交流#xff1a;import urllib.requestimport gzipimport jsonprint(------天气查询------)def get_weather_data() :city_na…刚入门python借鉴了论坛上前人写的天气查询程序通过使用中国天气网的API接口来实现如图贴上源代码希望大家评论交流import urllib.requestimport gzipimport jsonprint(------天气查询------)def get_weather_data() :city_name input(请输入要查询的城市名称)url1 http://wthrcdn.etouch.cn/weather_mini?cityurllib.parse.quote(city_name)url2 http://wthrcdn.etouch.cn/weather_mini?citykey101010100#网址1只需要输入城市名网址2需要输入城市代码#print(url1)weather_data urllib.request.urlopen(url1).read()#读取网页数据weather_data gzip.decompress(weather_data).decode(utf-8)#解压网页数据weather_dict json.loads(weather_data)#将json数据转换为dict数据return weather_dictdef show_weather(weather_data):weather_dict weather_data#将json数据转换为dict数据if weather_dict.get(desc) invilad-citykey:print(你输入的城市名有误或者天气中心未收录你所在城市)elif weather_dict.get(desc) OK:forecast weather_dict.get(data).get(forecast)print(城市,weather_dict.get(data).get(city))print(温度,weather_dict.get(data).get(wendu)℃ )print(感冒,weather_dict.get(data).get(ganmao))print(风向,forecast[0].get(fengxiang))print(风级,forecast[0].get(fengli))print(高温,forecast[0].get(high))print(低温,forecast[0].get(low))print(天气,forecast[0].get(type))print(日期,forecast[0].get(date))print(*******************************)four_day_forecast input(是否要显示未来四天天气是/否)if four_day_forecast 是 or Y or y:for i in range(1,5):print(日期,forecast[i].get(date))print(风向,forecast[i].get(fengxiang))print(风级,forecast[i].get(fengli))print(高温,forecast[i].get(high))print(低温,forecast[i].get(low))print(天气,forecast[i].get(type))print(--------------------------)print(***********************************)show_weather(get_weather_data())