EXERCISE TOPIC▼
- Access exercises (91)
- C# exercises (79)
- Excel exercises (278)
- Power Apps exercises (13)
- Power Automate exercises (18)
- Power BI exercises (139)
- Power Platform exercises (157)
- Python exercises (28)
- Report Builder exercises (141)
- SQL exercises (198)
- SSAS exercises (51)
- SSIS exercises (46)
- SSRS exercises (99)
- VBA exercises (85)
- Visual Basic exercises (46)
PYTHON EXERCISES▼
PYTHON EXERCISES▼
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.
Software ==> | Python (28 exercises) |
Version ==> | Latest version |
Topic ==> | Functions (3 exercises) |
Level ==> | Average difficulty |
Subject ==> | Python training |
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:
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!