3 Star 0 Fork 1

mirrors_trekhleb/learn-python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_while.py 960 Bytes
一键复制 编辑 原始数据 按行查看 历史
Oleksii Trekhleb 提交于 2018-08-29 23:23 +08:00 . Add Python scripts.
"""WHILE statement
@see: https://docs.python.org/3/tutorial/controlflow.html
@see: https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
The while loop executes as long as the condition remains true. In Python, like in C, any
non-zero integer value is true; zero is false. The condition may also be a string or list
value, in fact any sequence; anything with a non-zero length is true, empty sequences are
false.
The test used in the example is a simple comparison. The standard comparison operators are
written the same as in C: < (less than), > (greater than), == (equal to), <= (less than or
equal to), >= (greater than or equal to) and != (not equal to).
"""
def test_while_statement():
"""WHILE statement"""
# Let's raise the number to certain power using while loop.
number = 2
power = 5
result = 1
while power > 0:
result *= number
power -= 1
# 2^5 = 32
assert result == 32
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trekhleb/learn-python.git
git@gitee.com:mirrors_trekhleb/learn-python.git
mirrors_trekhleb
learn-python
learn-python
master

搜索帮助