Advertisement
immanual1

sumdigit.py

Jan 13th, 2025
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.21 KB | None | 0 0
  1. def sum_of_digits(n):
  2. sum = 0
  3. while n != 0:
  4. sum += n % 10
  5. n //= 10
  6. return sum
  7.  
  8. num = int(input("Enter a number: "))
  9. total_sum = sum_of_digits(num)
  10. print("Sum of digits:", total_sum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement