当前位置:首页 > Python教程 > python技巧

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

求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

 

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


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐