Given a string, write a program to return the sum and average of the digits of all numbers that appear in the string, ignoring all other characters.
stri =input()
sum=0
count=0
avrg=0
for i in stri:
if i.isdigit():
i =int(i)
sum = sum+i
count =count+1
else:
pass
if sum>0:
avrg = sum/count
print ("Sum=", sum, "average =", avrg)
Comments
Leave a comment