Back

Write a code get an integer number as input and print the sum of the digits. Input Description: A single line containing an integer. Output Description: Print the sum of the digits of the integer. Sample Input : 124 Sample Output : 7

Created 1 year ago
224 Views
2 Comments
kalaivananGUgS2a
@kalaivananGUgS2a
kalaivananGUgS2a
@kalaivananGUgS2aProfile is locked. Login

number = int(input("Enter an integer: "))

sum_of_digits = 0

while number > 0:

digit = number % 10

sum_of_digits += digit

number //= 10

print("Sum of digits:", sum_of_digits)

code is not executing in python3 can someone help with this

Comments (2)
Please login to comment.