3
I have a list of integers larger than zero. I need to identify the one with the largest number of divisors. For this I created three functions: one that lists, one that returns all divisors of all elements of a list and another that filters which element has more divisors. The problem is that I can’t get the function moreDivistors to directly receive a list of only the elements (without the splitters), you know? If I call the function2 (listingDivisors) within function 3 (moreDivisors) always gives way. However if I call manually, it works well. I’ve tried all possibilities and nothing. How do I call the first function in the second to make it work by getting the raw list?
function 1 (sort lists) def Qs(list): if list==[]: Return [] Else: pivot=list[0] Return (Qs([x for x in list if xpivor]))
function 2: returns 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)
function 3 returns the number of one with the largest number of divisors
def maisDivisores(list):
if len(lista)==[]:
return "Nenhum número."
else:
**lista=listaDivisores(lista)**
when adding this command line the code does not execute if int(Len(list))==1: List Return[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
SOLVED!! Excludes the first function. I made only one. Hence what I did... from the raw list I took the first element destructively. With a list comprehension, I create a list with his divisors, if the list is different from empty I enter the function again, until I get all the elements then it will give me a list with the divisors of all. then just compare and return the element that has the largest number of splitters
– Márcio Arruda