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.
import re
inp_str = input()
nums = list(map(int, re.findall(r'\d+', inp_str)))
print(sum(nums))
print(sum(nums)/len(nums))
Comments
Leave a comment