Question #242842

Give a string writen a program to return the sum and average of the digits of all numbers that appear in the string igonring all other characters

Expert's answer

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
LATEST TUTORIALS
APPROVED BY CLIENTS