I need to write a program that generates a list of N elements ranging from 1 to 10 then display the list on the screen. Remove from the list all elements that are multiples of k or m (enter k and m from the keyboard). For example, remove all numbers that are multiples of 3 or 5.
import random
n = int (input ('Enter the number of list items') )
c = [random.randint (1, 10) for i in range (n) ]
print (c)
k = int (input ('Enter the number from which we will determine the multiplicity.') )
m = int (input ('Enter the number from which we will determine the multiplicity.') )
for i in n:
if c % k == 0 and c % m == 0
c.remove (i)
print(c)
>Solution :
Change this:
for i in n:
if c % k == 0 and c % m == 0
c.remove (i)
To this:
c = [x for x in c if x % k != 0 and x % m != 0]