The output should contain the sum and average of the numbers that appear in the string.
Note: Round the average value to two decimal places
sample input:
I am 25 years and 10 months old
output
37
17.5
def sum_and_average(s1):
sumd = 0
count=0
temp = "0"
for c in s1:
if (c.isdigit()):
temp += c
else:
if temp!="0":
count+=1
sumd+= int(temp)
temp = "0"
sumd += int(temp)
print(sumd)
print(sumd/ count)
if __name__ == '__main__':
string1=input("Enter the string:\n")
sum_and_average(string1)
Comments
Leave a comment