0

WHILE LOOP CHANGED question: How do I change the code to calculate and output the sum of all digits of the input number.

n = int(input()) length = 0 while n > 0: n //= 10 length += 1 print(length)

4th Jun 2021, 7:48 PM
Frank
3 Respostas
+ 2
n=int(input()) sum_=0 while n!=0: sum_+=n%10 n=n//10 print(sum_) #input : 123 #output : 6
4th Jun 2021, 8:08 PM
Ratnapal Shende
Ratnapal Shende - avatar
0
n=10 print((n+1)*n//2) #print(sum(range(n+1)))
4th Jun 2021, 10:19 PM
Steven M
Steven M - avatar
0
Idk why but this one whooped on me lol
31st Jan 2022, 9:26 PM
Justin