Digit Sum in Strings

    0

    0

    Mahendra Kumar

    beginnerlogicstrings

    Python Program to Compute Sum of Digits in a String

    # 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)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    Legal
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.