-1

I tried to solve this problem with python 2.7. I just began programming so I hoped that one of you amazing people could help me out!

this is what i currently have:

my_list = [2,3,4,5,6,7,8,9,10,11,]


for a in range(0, 39916800):

    if (a % my_list == 0):
        print("a")

THE ANSWER =

a = 2*3*4*5*6*7*8*9*10*11

a = a-1

for a in range (0,a):
if a % 2 == 0:
    if a % 3 ==0:
        if a % 4 ==0:
            if a % 5 ==0:
                if a % 6 ==0:
                    if a % 7 ==0:
                        if a % 8 ==0:
                            if a % 9 ==0:
                                if a % 10 ==0:
                                    if a % 11 ==0:
                                        print a
                                        if a > 1:
                                            break
redouan
  • 5
  • 1
  • I saw that topic, but I didn't really understood the way they solved the problem. Can someone tell me what's wrong with the code I wrote and where I can improve it. – redouan Sep 17 '17 at 15:28
  • I found the answer. a = 2*3*4*5*6*7*8*9*10*11 a = a-1 for a in range (0,39916800): if a% 2 == 0: if a % 3 ==0: if a % 4 ==0: if a % 5 ==0: if a % 6 ==0: if a % 7 ==0: if a % 8 ==0: if a % 9 ==0: if a % 10 ==0: if a % 11 ==0: print a – redouan Sep 17 '17 at 17:11

1 Answers1

0

First, I think your logic is a bit off. I would loop over the list.

This code doesn't exactly answer your problem, but it seems like a good stepping stone

my_list = [2,3,4,5,6]

for a in my_list:
    for sub in range(len(my_list)): # nesting loop. pretty much for each num, it goes over each num in mylist again
        if a % my_list[sub] == 0:
            pass # nothing is required at this step, pass just allows the if to print or no nothing if the conditional is true
            if a == len(my_list):
                print(a)
  • a = 2*3*4*5*6*7*8*9*10*11 a = a-1 for a in range (0,a): if a % 2 == 0: if a % 3 ==0: if a % 4 ==0: if a % 5 ==0: if a % 6 ==0: if a % 7 ==0: if a % 8 ==0: if a % 9 ==0: if a % 10 ==0: if a % 11 ==0: print a if a > 1: break – redouan Sep 19 '17 at 19:04