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
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)
Comments
Leave a comment