鱼C论坛

 找回密码
 立即注册
楼主: python_小白

[作品展示] 新人天气查询程序,绝对可用

    [复制链接]
发表于 2019-5-22 15:14:05 | 显示全部楼层
6666666666666666666
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-22 15:29:06 | 显示全部楼层
66
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-23 18:54:52 | 显示全部楼层
新手 学一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-24 10:14:02 | 显示全部楼层
a
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-24 14:17:43 | 显示全部楼层
1
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-24 16:43:10 | 显示全部楼层
学习学习
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-24 21:40:21 | 显示全部楼层
6
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-24 23:19:10 | 显示全部楼层
查询天气
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-25 12:28:41 | 显示全部楼层
学习学习
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-28 22:19:05 | 显示全部楼层
thank you very much
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-28 23:50:39 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-29 03:00:37 | 显示全部楼层
来学习一下
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-29 10:36:30 | 显示全部楼层
6666
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-29 11:06:53 | 显示全部楼层
66666
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-29 11:13:46 From FishC Mobile | 显示全部楼层
看看
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-29 11:41:42 | 显示全部楼层
学习学习
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-29 13:55:19 | 显示全部楼层
本帖最后由 txl1988 于 2019-5-29 13:57 编辑
七日 发表于 2019-5-16 12:42
无论回答是或者否或者直接回车,都会显示四天的天气啊

  1. import urllib.request
  2. import gzip
  3. import json
  4. print('------天气查询------')
  5. def get_weather_data() :
  6.     city_name = input('请输入要查询的城市名称:')
  7.     url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name)
  8.     url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
  9.     #网址1只需要输入城市名,网址2需要输入城市代码
  10.     #print(url1)
  11.     weather_data = urllib.request.urlopen(url1).read()
  12.     #读取网页数据
  13.     weather_data = gzip.decompress(weather_data).decode('utf-8')
  14.     #解压网页数据
  15.     weather_dict = json.loads(weather_data)
  16.     #将json数据转换为dict数据
  17.     return weather_dict

  18. def show_weather(weather_data):
  19.     weather_dict = weather_data
  20.     #将json数据转换为dict数据
  21.     if weather_dict.get('desc') == 'invilad-citykey':
  22.         print('你输入的城市名有误,或者天气中心未收录你所在城市')
  23.     elif weather_dict.get('desc') =='OK':
  24.         forecast = weather_dict.get('data').get('forecast')
  25.         print('城市:',weather_dict.get('data').get('city'))
  26.         print('温度:',weather_dict.get('data').get('wendu')+'℃ ')
  27.         print('感冒:',weather_dict.get('data').get('ganmao'))
  28.         print('风向:',forecast[0].get('fengxiang'))
  29.         print('风级:',forecast[0].get('fengli'))
  30.         print('高温:',forecast[0].get('high'))
  31.         print('低温:',forecast[0].get('low'))
  32.         print('天气:',forecast[0].get('type'))
  33.         print('日期:',forecast[0].get('date'))
  34.         print('*******************************')

  35.     four_day_forecast =input('是否要显示未来四天天气,是/否:')
  36.    # 用判断一个元素是否在一个列表中,
  37.     key = ['是','Y','y']
  38.     if four_day_forecast in key:
  39.         for i in range(1,5):
  40.             print('日期:',forecast[i].get('date'))
  41.             print('风向:',forecast[i].get('fengxiang'))
  42.             print('风级:',forecast[i].get('fengli'))
  43.             print('高温:',forecast[i].get('high'))
  44.             print('低温:',forecast[i].get('low'))
  45.             print('天气:',forecast[i].get('type'))
  46.             print('--------------------------')
  47.     else:
  48.         # 如果不在列表中,给个提示
  49.         print('再见')

  50.     print('***********************************')

  51. show_weather(get_weather_data())
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-30 15:00:52 | 显示全部楼层
好玩
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-30 21:23:11 | 显示全部楼层
感谢分享
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-5-30 21:55:28 | 显示全部楼层
厉害

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 16:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表