Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Fundamentals Study Guide

Authors: Dr. Sergio Pisano

1st Edition

B09K1WW84J, 979-8985115307

More Books

Students also viewed these Databases questions