Question #231252

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.


Expert's answer

string = input()
count = 0
sum = 0
for symb in string:
  if symb.isdigit():
    sum += int(symb)
    count+=1
print(f'Sum: {sum}')
print(f'Average of the digits: {sum/count}')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS