1
Write a program that receives an integer number in the input, calculate and print 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 an entire division by throwing away the rest, that is, that which is less than the divisor; The operator "%" returns only the rest of the entire division by throwing away the result, that is, all that is greater than or equal to the divisor.
I made the code, however, it has a repeat bug that I can’t fix. Can someone help me?
x=int(input("Digite um número para que seus digitos sejam somados: "))
soma=0
while (x>0):
resto = (x // 10)%10
resto_cont=(x%10)
resto_cont2=(x//100)
soma = resto + resto_cont + resto_cont2
print("valor é", soma)
Ah, thank you so much for your help!!!!
– Larissa Silva