Answer to Question #224012 in Python for hemanth

Question #224012

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

Input


The input will be a single line containing a string.

Output


The output should contain the sum and average of the numbers that appear in the string.



 Note: Round the average value to two decimal places.


Explanation

For example, if the given string is "I am 25 years and 10 months old", 

the numbers are 25, 10. Your code should print the sum of the numbers(35)

and the average of the numbers(17.5) in the new line.

Sample Input 1

I am 25 years and 10 months old

output:

35

17.5

sample Input 2

Lear4 python7

output:

11

5.5

sample Input 3

Anjali25 is python4 Expert

output:

29

14.5 



1
Expert's answer
2021-08-09T02:32:14-0400
import re

numbers = [int(n) for n in re.findall(r'\d+', input())]
if numbers:
    print(sum(numbers))
    print(round(sum(numbers) / len(numbers), 2))

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