100道python基础题——(12)

题:编写一个程序,它将找到1000到3000之间的所有这些数字(均包括在内),这样数字的每个数字都是偶数。
获得的数字应以逗号分隔的顺序打印在一行上。

提示:如果输入数据被提供给问题,则应该假定它是控制台输入。

☆☆☆☆

    x = str(s) #数字转换成字符串
    if (int(x[0])%2==0) and (int(x[1])%2==0) and (int(x[2])%2==0) and (int(x[3])%2==0):#字符串取出每一位,并转成数字(int)类型 ,必须!

☆☆☆☆
a = []
for s in range(1000,3001):
x = str(s)
if (int(x[0])%2==0) and (int(x[1])%2==0) and (int(x[2])%2==0) and (int(x[3])%2==0):
a.append(x)
print(','.join(a))
posted on 2023-03-20 19:14  第几个梦乘风起  阅读(59)  评论(0)    收藏  举报