add all input digits python

Solutions on MaxInterview for add all input digits python by the best coders in the world

showing results for - "add all input digits python"
Luca
01 Sep 2016
1# Program published on https://beginnersbook.com
2
3# Python program to sum all the digits of an input number
4
5num = int(input("Enter a Number: "))
6result = 0
7hold = num
8
9# while loop to iterate through all the digits of input number
10while num > 0:
11    rem = num % 10
12    result = result + rem
13    num = int(num/10)
14
15# displaying output
16print("Sum of all digits of", hold, "is: ", result)