Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I don't know how to correctly remove multiples of k and m from the list)

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading