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
- Get the input from user.
- Use modulo to extract the digits from the number.
- 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