I have a list of integers greater than zero. I need to identify the one with the largest number of divisors. For this I have created three functions: one that orders list, one that returns all the divisors of all the elements of a list and another that filters which element has more divisors. The problem is that I can not make the function moreDivisores directly receive a list with only the elements (without the dividers), you see? If I call function2 (listDivisors) within function 3 (moreDivisores) always gives stick. However if I call manually, it works fine. I've tried all the possibilities and nothing. How do I call the first function in the second so that it works by receiving the raw list?
function1 (sorts lists) def qs (list): if list == []: return [] else: pivor = list [0] return (qs ([x for x in list if xpivor]))
function2: returns the divisors of a number
def listaDivisores(lista):
if lista == []:
return []
else:
lista=qs(lista)
resultado=[]
resultado.append((lista[0],[y for y in range(1,((lista[0])+1)) if (int(lista[0]))%y==0]))
return resultado+listaDivisores(lista[1:])
return listaDivisores(lista)
function3 returns the number of one with the largest number of divisors
def moreDivisores (list):
if len(lista)==[]:
return "Nenhum número."
else:
**lista=listaDivisores(lista)**
When you add this command line the code does not execute if int (len (list)) == 1: return list [0] elif int (len (list [0] [1]))
ERROR LOG
>>> maisDivisores(lista)
Traceback (most recent call last):
File "<pyshell#499>", line 1, in <module>
maisDivisores(lista)
File "D:/Google Drive/CIn/Prog1/EE2.py", line 58, in maisDivisores
return maisDivisores(lista)
File "D:/Google Drive/CIn/Prog1/EE2.py", line 46, in maisDivisores
lista=listaDivisores(lista)
File "D:/Google Drive/CIn/Prog1/EE2.py", line 35, in listaDivisores
resultado.append((lista[0],[y for y in range(1,((lista[0])+1)) if (int(lista[0]))%y==0]))
TypeError: can only concatenate tuple (not "int") to tuple