0
This Python code is about divisors but it does't work .. why?
This code receives a list of integers and returns an integer which has the most divisors For Example: a = [4, 8, 12, 18] 4 = 1, 4 8 = 1, 2, 4, 8 12 = 1, 2, 3, 4, 6, 12 18 = 1, 2, 3, 6, 9, 18 And if 2 integers has the same number of divisors (For Example 12 and 18 both has 6 disors) then it should return the larger integer(18) https://code.sololearn.com/chWQh8KC3t24/?ref=app
4 Answers
+ 3
First sort() method works on original list so dont return new list.
a.sort() # b= a.sort() b= none, a is sorted
+ 2
Ali Go step by step.Are you tried that change?
I tested it that you need pass original list..
a.sort()
Pass list a to function.
By your approach, you need to find maximum value of nr_divisors list from end. So first you need to reverse the result list nr_divisors. Index of max value is the index of element of reversed original list. Seems a bit of complicated way for me..
I just try, find divisors and then store maximum divisor and item in variables x, y in each iteration.
Return the item y finally.
+ 1
Jayakrishna🇮🇳 can u please debug it and post the debuged version
0
Jayakrishna🇮🇳 Thank u so much ⚘⚘⚘