Answer to Question #193793 in Python for R.bhavani

Question #193793

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)


1
Expert's answer
2021-05-15T13:47:13-0400
import re
inputString= input()
numbers=[int(s) for s in re.findall(r'\d+', inputString)]
print(sum(numbers))
print(sum(numbers)/len(numbers))
        




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS