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.Explanation For example, if the given string is "I am 25 years and 10 months old", the digits of all numbers that appear in the string are 2, 5, 1, 0. Your code should print the sum of all digits(8) and the average of all digits(2.0) in the new line. Sample Input 1 I am 25 years and 10 months old Sample Output 1 8 2.0 Sample Input 2 Tech Foundation 35567 Sample Output 2 26 5.2
1
Expert's answer
2021-10-29T00:54:47-0400
n=input("Enter string: ")
sum=0
avg=0
l=0
for i in n:
if i.isdigit():
sum+=int(i)
l+=1
else:
None
avg=round((sum/l),)
print("Sum=",sum,"\n Average=",avg)
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment