1.计算1-100中偶数之和
方法一:
n = 0
sum = 0
while n <= 100:
if n % 2 == 0:
sum = sum + n
n = n + 1
print(sum)
方法二:
n = 0
sum = 0
while n <= 100:
sum = sum + n
n = n + 2
print(sum)
输出结果:2550
2.打印九九乘法表
m = 1
while m <= 9:
n = 1
ji = m * n
while n < m:
print(f'{n} * {m} = {ji}',end='\t')
n = n + 1
print(f'{n} * {m} = {ji}')
m = m + 1