Answer to Question #243787 in Python for Rishi

Question #243787
Give a string writen a program to return the sum and average of the number that appear in the string igonring all other characters
1
Expert's answer
2021-09-30T00:57:52-0400
string1 = input('Enter string here ')
list1 = []
for i in string1.split(' '):
     if i.isnumeric() == True:
        list1.append(float(i))
print('The sum is {} and the average of the numbers in the given string is {}'.format(sum(list1),sum(list1)/len(list1)))

Enter string here 'I am 20 years and 11 months'
The sum is 31.0 and the average of the numbers in the given string is 15.5

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