def sum_of_digits(number): sum = 0 while number > 0: digit = number % 10 sum += digit number = number // 10 return sum # Example usage number = 12345 print("Sum of the digits:", sum_of_digits(number))
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter