Sum of the digits present in a list
PYTHON CODE FOR FINDING SUM OF DIGITS PRESENT IN A STRING METHOD-1 USING LOOP: a=input("Enter a string") s=0 for i in a: if i.isdigit(): s=s+int(i) print("Sum of the digit present in the string is:",s) OUTPUT: METHOD-2 my converting a string in list: a=input("Enter a string") m=list(a) s=0 for i in m: if i.isdigit(): s=s+int(i) print("Sum of the digit present in the string is:",s)
Comments
Post a Comment