0

divisor in python

hi guys, I need a code in python than can find out divisors of a number then find the most divisors of it. for exp 672 have 24 divisors. this is my attempt to resolve this problem: answer = 0; temp_1 =0; temp_2 = 0; while True: temp_1=0; number = int(input('Enter your number: ')) if number <=0: break; for i in range(1, number+1): if number % i == 0: temp_1+=1; if temp_1>=temp_2: if(number > answer): answer = number; temp_2 = temp_1 print('answer = ',answer); for i in range(1,answer+1): if answer % i ==0: print(i); input('')

2nd Apr 2020, 9:53 AM
Rohan Garshasebi
Rohan Garshasebi - avatar
1 Answer
+ 2
Run a loop that checks if number is divisor of given number (n%i ==0) Add +1 to the counter variable if condition is true.
2nd Apr 2020, 9:57 AM
Bhavya
Bhavya - avatar