标签:输出 else 基本语法 int 包括 lse n+1 cond 示例
基本语法:
while condition:
code...
示例:
1.输出1到10,不包括7
n = 1
while n < 11:
if n == 7:
pass
else:
print(n)
n = n+1
2.计算1-100所有数之和
n = 1
s = 0
while n < 101:
s = s + n
n = n + 1
print(s)
3.计算1-2+3-4+5-6...99
n = 1
s = 0
while n < 101:
if n % 2 == 0:
s = s - n
else:
s = s + n
n = n + 1
print(s)
标签:输出 else 基本语法 int 包括 lse n+1 cond 示例
原文地址:https://www.cnblogs.com/wang-jie-devops/p/9733235.html