Answer to Question #225344 in Python for chotu

Question #225344

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.


1
Expert's answer
2021-08-11T14:17:17-0400
stri =input()
sum=0
count=0
avrg=0
for i in stri:
	if i.isdigit():
		i =int(i)
		sum = sum+i
		count =count+1
	else:
		pass
if sum>0:		
	avrg = sum/count
print ("Sum=", sum, "average =", avrg)

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