def ComputeSum(num): #user-defined function
          sum = 0
          while (num != 0):  
              sum += (num % 10) 
              num //= 10
          return sum
      # take input
      num = int(input('Enter a number: '))
      # calling function & display result
      print('Sum of digits in number =', ComputeSum(num))
      
      Python language logo

      Sum of Digits

      beginner
      basicMaths
      digitSum

      Calculating the sum of the digits of a given number: Eg: 123 = 1 + 2 + 3 = 6

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.