mwq1122 发表于 2019-5-22 15:14:05

6666666666666666666

wangsiyang 发表于 2019-5-22 15:29:06

66

fishcckh 发表于 2019-5-23 18:54:52

新手 学一下

afeifeieiei 发表于 2019-5-24 10:14:02

a

xiaochuan 发表于 2019-5-24 14:17:43

1

启航的小鸟 发表于 2019-5-24 16:43:10

学习学习

一个小朋友们 发表于 2019-5-24 21:40:21

6

moduo320 发表于 2019-5-24 23:19:10

查询天气

DoKo 发表于 2019-5-25 12:28:41

学习学习

patter 发表于 2019-5-28 22:19:05

thank you very much

a3371730 发表于 2019-5-28 23:50:39

{:9_228:}{:9_228:}

sherlockeinstei 发表于 2019-5-29 03:00:37

来学习一下

Nyu菌 发表于 2019-5-29 10:36:30

6666

kucfire 发表于 2019-5-29 11:06:53

66666

czb. 发表于 2019-5-29 11:13:46

{:10_260:}{:10_260:}{:10_260:}{:10_260:}看看

1304687090 发表于 2019-5-29 11:41:42

学习学习

txl1988 发表于 2019-5-29 13:55:19

本帖最后由 txl1988 于 2019-5-29 13:57 编辑

七日 发表于 2019-5-16 12:42
无论回答是或者否或者直接回车,都会显示四天的天气啊

import urllib.request
import gzip
import json
print('------天气查询------')
def get_weather_data() :
    city_name = input('请输入要查询的城市名称:')
    url1 = 'http://wthrcdn.etouch.cn/weather_mini?city='+urllib.parse.quote(city_name)
    url2 = 'http://wthrcdn.etouch.cn/weather_mini?citykey=101010100'
    #网址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_dict

def 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.get('fengxiang'))
      print('风级:',forecast.get('fengli'))
      print('高温:',forecast.get('high'))
      print('低温:',forecast.get('low'))
      print('天气:',forecast.get('type'))
      print('日期:',forecast.get('date'))
      print('*******************************')

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

    print('***********************************')

show_weather(get_weather_data())

lihouyu001 发表于 2019-5-30 15:00:52

好玩

liuhaitaozky 发表于 2019-5-30 21:23:11

感谢分享

飞机大战 发表于 2019-5-30 21:55:28

厉害

页: 212 213 214 215 216 217 218 219 220 221 [222] 223 224 225 226 227 228 229 230 231
查看完整版本: 新人天气查询程序,绝对可用