我的第二个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)
Output an even number between 0 and 100

输出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)
Output the odd number between 0 and 100

 

posted @ 2017-09-28 14:43  fansik  阅读(232)  评论(0编辑  收藏  举报