Write a program that receives an integer in the input, computes and prints the sum of the digits of this number in the output. Example:
>>> Digite um número inteiro: 123
6
Tip: To separate the digits, remember: the //
operator makes a whole division throwing away the rest, ie, that which is smaller than the divisor; The %
operator returns only the rest of the integer division by throwing out the result, that is, everything that is greater than or equal to the divisor.
I have tried in many ways, but the result continues to give zero. I only have this attempt annotated because I've been doing it over:
n = int(input("Digite um número inteiro: "))
soma = 0
while (n > 0):
resto = n % 10
n = (n - resto)/10
soma = soma + resto
print("A soma dos números é: ", n)