Python: list index out of range

0

I'm doing a short program to try Python, one in which you choose two lists of numbers and it tells you how many numbers in the second list are multiples of all the numbers in the first

def esmultiplo (m,y,b):
if y % m != 0 and b == True:
        b = False
return b

def cuantosmultiplos (multiplos, lista):
n = 0
i = 0
j = 0
bool = True
for i in lista:
    for j in multiplos:
        bool = esmultiplo (multiplos[j], lista[i], bool)
    if bool == True:
        n = n + 1
return n

l = list(range(1,100))
m = [3,5]
n = 0
n = cuantosmultiplos(m, l)
print(n)

And the problem is that I get the following error

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-81-a52f103b79ab> in <module>()
      2 m = [3,5]
      3 n = 0
----> 4 n = cuantosmultiplos(m, l)
      5 print(n)

<ipython-input-80-3ed7d41f67dd> in cuantosmultiplos(multiplos, lista)
      6     for i in lista:
      7         for j in multiplos:
----> 8             bool = esmultiplo (multiplos[j - 1], lista[i - 1], bool)
      9         if bool == True:
     10             n = n + 1

IndexError: list index out of range

I have reviewed it several times and I do not know what I have wrong. I'm pretty new so it can be silly. Thanks in advance

    
asked by Juan Rodríguez 03.07.2018 в 18:44
source

1 answer

0

I think you should change this line
bool = esmultiplo (multiplos[j], lista[i], bool) by% bool = esmultiplo (j, i, bool)
When iterating with a for i in lista what you do is iterate over the list and poninedo each value in the variable i .

    
answered by 03.07.2018 / 18:50
source