-1
I need to create a program that shows the sum of all the divisors of a number, except this number itself.
Ex: the sum of the divisors of number 66 is 1 + 2 + 3 + 6 + 11 + 22 + 33 = 78
In case, I need to print only the 78, as output.
My program, however, is printing all divisors. How to change this, please? Follow my code below:
divisor = 1
numero = int(input('Informe um número inteiro e positivo: '))
if numero < 0:
numero = int(input('O número não pode ser negativo.\n Digite um número inteiro e positivo: '))
for divisor in range(divisor, numero):
if numero % divisor == 0:
print(divisor)
My code above returns, for example, if I type 66, the following:
1
2
3
6
11
22
33
Related: https://answall.com/q/456301/112052
– hkotsubo
This answers your question? How to quickly calculate the sum of dividers in Python?
– Marco Souza
Thank you. So it is that in fact hkotsubo had posted a simpler form containing functions and resources that I have studied so far. But his post is gone...
– EWSG
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site
– Maniero