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