我的第二个Python小程序
输出0-100之间的偶数:
# Author: fansik
# Description: Output an even number between 0 and 100
# method one
num = 0
while num <= 100:
if num % 2 == 0:
print(num)
num += 1
# method two
num2 = [x for x in range(0, 101, 2)]
print(num2)
输出0-100之间的奇数:
# Author: fansik
# Description: Output the odd number between 0 and 100
# method one
num = 0
while num <= 100:
if num % 2 == 1:
print(num)
num += 1
# method two
num2 = [x for x in range(1, 100, 2)]
print(num2)