Answer to Question #234024 in Python for rasi

Question #234024

Numbers in String - 1

Given a string, write a program to return the sum and average of the digits of all 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 digits of all numbers that appear in the string.

Note: Round the average value to two decimal places.input1-I am 25 years and 10 months old

output1-8
2.0

input2-Anjali25 is python4 Expert

output2-11
3.67
1
Expert's answer
2021-09-08T16:08:40-0400
n = input('Enter your string here: ')
list1 = []
for i in n:
    if i.isnumeric():
        list1.append(int(i))
print(sum(list1))
print(sum(list1)/len(list1))

Enter your string here: I am 25 years 10 months
8
2.0

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