# take input
      string = input("Enter any string: ")
      # find sum of digits
      sum_digit = 0
      for x in string:
          if x.isdigit():
              sum_digit += int(x)
      # display result
      print("Sum of digits =", sum_digit)
      
      Python language logo

      Digit Sum in Strings

      beginner
      logic
      strings

      Python Program to Compute Sum of Digits in a String

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.