Computer Science
Write a Python program to compute sum of digits of a given number.
Python
Python Control Flow
5 Likes
Answer
number = int(input("Enter a number: "))
sum_of_digits = 0
while number > 0:
digit = number % 10
sum_of_digits += digit
number = number // 10
print("Sum of digits:", sum_of_digits)
Output
Enter a number: 4556787
Sum of digits: 42
Answered By
2 Likes
Related Questions
Write a Python program to capitalize first and last letters of each word of a given string.
Write a Python program to remove duplicate characters of a given string.
Write a Python program to find the second most repeated word in a given string.
Write a Python program to change a given string to a new string where the first and last characters have been exchanged.