Python:如何选择仅包含特定数字的倍数?

时间:2019-08-31 10:41:40

标签: python-3.x

例如,从因子数字的所有倍数中,我想找到在整数的2位数字之一中具有数字“ d”的整数的数量。 n是我要搜索的倍数数量的限制。

def find_integers():
Factor=int(input("Enter Factor-digit:"))
d=int(input("Enter must-have-digit:"))
n=int(input("Enter the total number of integers:"))

for i in range(0,n):
    Multiples=(Factor*i)

我如何继续取出其中包含数字“ d”的倍数?

1 个答案:

答案 0 :(得分:0)

multiples=[x*2 for x in range(0,1000000)]
# get 1 million multiples of 2
print(list(filter(lambda x:"4" in str(x),multiples)))
# this only prints the values in multiples if the lambda function returns true
# it only returns true if the string "4" is in the string representation of the number

我希望这对您有帮助