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
Comments
Leave a comment