Answer to Question #247257 in Python for Raju

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.


1
Expert's answer
2021-10-06T01:26:39-0400
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS