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!
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:
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:
|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!