Ask Question
30 October, 23:15

Def sum_divisors (n) : sum = 1 # Return the sum of all divisors of n, not including n x=int (n**0.5) for i in range (2, (x//1) + 1) : if n%i==0: sum=sum+i if n%i==0 and n/i!=i: sum=sum + (n/i) return sum print (sum_divisors (0)) # 0 print (sum_divisors (3)) # Should sum of 1 # 1 print (sum_divisors (36)) # Should sum of 1+2+3+4+6+9+12+18 # 55 print (sum_divisors (102)) # Should be sum of 2+3+6+17+34+51 # 114

+3
Answers (1)
  1. 30 October, 23:31
    0
    This is a python program that counts the number of divisors of a given number and calculates the sum of the divisors.

    Explanation:

    The first line defines a function "sum_divisors" with an argument "n". The square root of the argument is converted to integer and assigned to the variable "x", then a for loop is used to iterate through the range 2 to the calculated nth number of divisors in the argument. The return keyword returns the sum value.

    The function is called with several arguments and printed with the print function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Def sum_divisors (n) : sum = 1 # Return the sum of all divisors of n, not including n x=int (n**0.5) for i in range (2, (x//1) + 1) : if ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers