+ 2
I wrote this code but the result is wrong... why?
Write a program that reads 20 numbers from the input and at the end prints the number that has the largest number of divisors and also print the number of divisors in the output. If there are several numbers in this state, print the largest one. Input: 767 665 999 895 907 796 561 914 719 819 555 529 672 933 882 869 801 660 879 985 Output will be: 672 24 https://code.sololearn.com/cxxP8QVSsl0N/?ref=app
7 Respostas
+ 2
#last lines corrections need :
nr_divisors = nr_divisors[::-1] #need to store back
idx = nr_divisors.index(max(nr_divisors)) #find index
return idx,max(nr_divisors) #return index, max divisors
largest, tedad = find_integer_with_most_divisors(*a)
print(a[::-1][largest], tedad) #largest is the index of element from end
+ 8
i have done a try not to correct the given code, but to simplify the complete approach.
you can find it in the attached file, also a description how it is working.
https://code.sololearn.com/cwqCTgoe5ULK/?ref=app
+ 3
Jayakrishna🇮🇳 Wooow thank u so much 🌹🌹🌹🌹
+ 2
You are taking a = [] . It creates each time a empty in loop. So you will have only last input in list. All will get replaced. Took it before loop start..
edit:
Ali
return input_list[len(nr_divisors) - 1] , nr_divisors[-1]
first one give you the original list last element.
and nr_divisors[-1] will return list last element..
+ 2
Jayakrishna🇮🇳 i'm really confused...
And what should i do next?
https://code.sololearn.com/cxxP8QVSsl0N/?ref=app
+ 2
Lothar Fabulous 👍👍👍
0
reverse list nr_divisors by nr_divisors[::-1] and find max number then it's index.
Index value is the index of largest divisors index from end to start. Ali