Write a Python program to calculate the sum of digits of a number.
Write a Python program to calculate the sum of digits of a number.
SOLUTION.
# Taking dynamic input from the user
num = int(input("Enter a number: "))
# Calculating the sum of digits
sum_of_digits = sum(int(digit) for digit in str(abs(num))) # Convert number to string, iterate over digits, and sum them
# Displaying the result
print("The sum of digits is:", sum_of_digits)