The given program calculates and outputs the number of digits in a given number using a while loop. During each iteration, the loop uses floor division to divide the given number by 10, thus dropping one digit. The process continues until the number has no more digits (n>0). You need to change the code to calculate and output the sum of all digits of the input number. My code is: n = int(input()) sum = 0 while n > 0: x = n % 10 sum += x n = n // 10 print(sum)

9/19/2021 7:47:52 PM

Nida Hanfi3 Answers

New Answer
Hot Today

css help
whats wrong with this code?
ES6 Destructuring doesnt work inside function()
What is "0b" in the output of this code and can it be excluded from the output ?
can you tell me how i make a diffrent number from rand becuase it did work with me
Please help with website responsiveness
can anybody help me
I'm learning koltin, is it worth it?
Why is it error?
Progress bar animation

Sololearn Inc.

535 Mission Street, Suite 1591San Francisco, CA 94105

© 2022 Sololearn, Inc.

Send us a message