Python | Functions exercise | Write some functions to make it easier to get text statistics

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

You can learn how to do this exercise if you attend the course listed below!

Software ==> Python  (25 exercises)
Version ==> Latest version
Topic ==> Functions  (3 exercises)
Level ==> Average difficulty
Classroom ==> Python programming
Online ==> Python programming
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Open the file in the above folder to see some quotations.  Your aim for this exercise is to print out some statistics about them:

Quotes and stats

For each quotation we want to show the number of words (as well as the longest one) to give the output shown above.

To help you do this, write these three functions:

Function Arguments Returns
get_words A string of text A list of the words in the string of text, with new line characters removed.
count_words A list of words The number of items in the list of words (this should be a single line of code!).
longest_word A list of words The longest word in a list (see note below).

To get the longest word in a list, use the max function with a key - for example:

# get the longest word in the list of words

return max(words, key=len).upper()

You should now be able to complete your code to print out the output shown at the start of the exercise, and as a bonus have some useful functions which you can call from other programs in the future! 

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 0 threads Add post