question is related to number string i passed two test cases as 1. I am 25 years and 10 months old---output(sum is 30, avg is 17.5) 2. tech foundation 35567 output(sum is 35567, avg is 35567.0)---got 2 text cases
but iam not getting 3. anjali25 is python4 expert output(sum=29, avg=14.5)
a=input().split()
sum=0
count=0
for i in a:
is_digit=i.isdigit()
if is_digit:
number=i
count+=1
sum=sum+int(number)
print(sum)
avg=sum/count
print(avg)
import re
inputString= input()
numbers=[int(s) for s in re.findall(r'\d+', inputString)]
print(sum(numbers))
print(sum(numbers)/len(numbers))
Comments
Leave a comment