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))
LATEST TUTORIALS
APPROVED BY CLIENTS