Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Find Sum of digits from given Number using while Loop


In this example shows, how to find sum of digits from given number using whileloop.

Steps
  1. Get the input from user.
  2. Use modulo to extract the digits from the number.
  3. Divide to shorten the number after the digit has been extracted.
Example:
Example.py
a = int(input("Enter the Value :"))
sum = 0
while (a!=0):
    digit = int(a%10)
    sum = sum+digit
    a = a//10
print(sum)

Output

Enter the Value :12345
15

Prev Next