Question #247257

Numbers in String - 2

Given a string, write a program to return the sum and average of the numbers that appear in the string, ignoring all other characters.


Expert's answer

import re

inp_str = input()

nums = list(map(int, re.findall(r'\d+', inp_str)))

print(sum(nums))
print(sum(nums)/len(nums))

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