Question: Create Python 3 code that satisfies the following: def average_sentence(s): average_sentence. This function must return the string The average of the digits in the string

Create Python 3 code that satisfies the following:

def average_sentence(s): """average_sentence. This function must return the string "The average of the digits in the string 's' is N.NN.". The number N.NN is the average of any digits (0-9) found in the string. If there are no digits N.NN = 0.00. There must always be 2 decimal places.

Parameters: s (str): A string of characters, potentially including digits

Returns: new_s (str): "The average of the digits in the string 's' is N.NN." s is the original string. N.NN is the average (mean) of the number of digits (0-9) found in the string. If there are no digits N.NN = 0.00. """

Test cases should be:

print('average_sentence') test(average_sentence("123455679"), "The average of the digits in the string '123455679' is 4.67.") test(average_sentence(""), "The average of the digits in the string '' is 0.00.") test(average_sentence("Python is a programming language"), "The average of the digits in the string 'Python is a programming language' is 0.00.") test(average_sentence("Python begins indexing into strings at position 0"), "The average of the digits in the string 'Python begins indexing into strings at position 0' is 0.00.") test(average_sentence( "Python uses negative indexing so the last letter in a string is at position -1"), "The average of the digits in the string 'Python uses negative indexing so the last letter in a string is at position -1' is 1.00.") test(average_sentence( "The address of UTM is 3359 Mississauga Rd, Mississauga, ON L5L 1C6"), "The average of the digits in the string 'The address of UTM is 3359 Mississauga Rd, Mississauga, ON L5L 1C6' is 4.57.") test(average_sentence("Christmas falls on December 25 each year in Canada"), "The average of the digits in the string 'Christmas falls on December 25 each year in Canada' is 3.50.")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!