Answer to Question #202709 in Python for sudheer

Question #202709

inputString =input("");

sumDigits =0

numberDigits=0

# Looping through a string.

for character in inputString:

  if (character.isdigit()):

    # Calculate the sum of the digits of all numbers that appear in the string

    sumDigits+=int(character)

    numberDigits+=1

# Calculate the average of the digits of all numbers that appear in the string

average=sumDigits/numberDigits

# Print the sum of all digits(8) 

print(str(sumDigits))

# Print the average of all digits(2.0) in the new line.

print("%.1f" % average)

input:

Anjali25 is python4 Expert

ouput:
11
3.7
the output should be like this:
11
3.67
1
Expert's answer
2021-06-03T13:42:12-0400
inputString =input("");
sumDigits =0
numberDigits=0
# Looping through a string.
for character in inputString:
  if (character.isdigit()):
    # Calculate the sum of the digits of all numbers that appear in the string
    sumDigits+=int(character)
    numberDigits+=1
# Calculate the average of the digits of all numbers that appear in the string
average=sumDigits/numberDigits
# Print the sum of all digits(8) 
print(str(sumDigits))
print("%.2f" % average)




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