设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【Python 第44课】 查天气(2)

  [复制链接]

1

主题

0

好友

98

积分

注册会员

Rank: 2

楼主
发表于 2014-3-16 23:35:59 |显示全部楼层
  1. while qw==True:
  2.     if cityname=='q' or cityname=='Q':
  3.         print'退出'
  4.         qw=False
  5.     else:
  6.         if citycode:
  7.             url='http://www.weather.com.cn/data/cityinfo/%s.html' % citycode
  8.             content=urllib2.urlopen(url).read()
  9.             print content
  10.         else:
  11.             print'sorry'
复制代码
while语句哪里不对吗?死循环了
你想查哪个城市的天气?
北京
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
{"weatherinfo":{"city":"北京","cityid":"101010100","temp1":"5℃","temp2":"19℃","weather":"多云转晴","img1":"n1.gif","img2":"d0.gif","ptime":"18:00"}}
回复

使用道具 举报

1

主题

0

好友

98

积分

注册会员

Rank: 2

沙发
发表于 2014-3-17 11:06:16 |显示全部楼层
crossin先生 发表于 2014-3-17 10:18
你的while本身确实是个死循环,在while没有修改退出条件的地方。可以修改的那条语句一直不会执行到。
除 ...

确实是  非常感谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-3 15:04 , Processed in 0.027769 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部