number = 123 # the number you want summed up
sum_of_digits = 0
for digit in str(number):
sum_of_digits += int(digit)
print(sum_of_digits) # printing the final sum of number
num = int(input("Enter the number: "))
sum_of_digits = 0
while num > 0:
digit = num % 10
num //= 10
sum_of_digits += digit
print("The sum of digits is", sum_of_digits)
# Here is the short version
number = 159
sum((int(n) for n in str(abs(number))))
num = input("Enter your number: ")
result = 0
for n in str(num):
result += int(n)
print("Result: ",result)
#code by fawlid
# Python program to
# compute sum of digits in
# number.
# Function to get sum of digits
def getSum(n):
strr = str(n)
list_of_number = list(map(int, strr.strip()))
return sum(list_of_number)
n = 12345
print(getSum(n))