, если вы не хотите делать '7' in number
и математически сделать это, вот как вы можете
n = 7
i = 0
j = 100
# largest_multiple_of_n_smaller_than_j = (j - j%n) # 100 - 100%7 --> 100 -2 --> 98
# 98//7 --> 14
# therefore we can say 7 multiply i( where i goes from 0 --> 14) will be less than equal to 100
multiples_of_n = [n*i for i in range(0, ((j - j%n) // n) +1)] # 0 7 14 21 ....98
# 17 27 37..(dont pick 77 here)..97 and 71 72 73...77..79
contains_n = [i*10+n for i in range(1,10) if i != n] + [n*10+x for x in range(1,10) if (n*10+x) % n !=0]
'''
or use this
contains_n = [x for x in range(10+n,j,10) if x != n*11] + [x for x in range(n*10+1,n*10+10) if x % n !=0]
'''
mult_and_contain_n = sorted(multiples_of_n + contains_n)
print(mult_and_contain_n)
Вывод
n = 7
[0, 7, 14, 17, 21, 27, 28, 35, 37, 42, 47, 49, 56, 57, 63, 67, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 84, 87, 91, 97, 98]
n = 5
[0, 5, 10, 15, 15, 20, 25, 25, 30, 35, 35, 40, 45, 45, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 65, 65, 70, 75, 75, 80, 85, 85, 90, 95, 95, 100]