You can download this code by clicking the button below.
This code is now available for download.
Calculate the sum of the digits of an integer
Technology Stack : Built-in functions isinstance, sum, abs, str, for loop
Code Type : Function
Code Difficulty :
def sum_of_digits(number):
if not isinstance(number, int):
raise ValueError("Input must be an integer")
return sum(int(digit) for digit in str(abs(number)))