首页 > 编程语言 > 详细

MIT Python 第三课一般代码样式 循环式程序 第15分钟:求16的平方根:4

时间:2015-06-25 11:46:29      阅读:283      评论:0      收藏:0      [点我收藏+]

求16的平方根:4

>>> #显示16的平方根
>>> x=16
>>> ans=0
>>> while ans*ans<16:
    ans=ans+1
    print(ans)

    
1
2
3
4
>>> print(ans)
4
>>> 

终极测试中应该是<0 没有=0

>>> x=16
>>> ans=0
>>> while ans*ans<=x:
    ans=ans+1
    print(ans)

    
1
2
3
4
5

 

MIT Python 第三课一般代码样式 循环式程序 第15分钟:求16的平方根:4

原文:http://www.cnblogs.com/hhj187/p/4599421.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!