Python Online Compiler
Example: Sum of Digits of a Number in Python using For loop
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Sum of Digits of a Number in Python using For loop print ("Enter the integer number::\n") x, sum, m = int(input()), 0, None print ("The sum of ", x, " digits is = ", end="") while x > 0: m = x % 10 m = int (m) sum = sum + m x = x / 10 x = int (x) print (sum, "\n")
1459
Output
Clear
ADVERTISEMENTS