Python | Functions exercise | Create a function to print out an underlined title

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 ==> Relatively easy
Classroom ==> Python programming
Online ==> Python programming

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.

It's often nice to print titles out with underlining - like this, in fact:

Printing titles

The underlining for each title is the same width as its text.

 

Here's some code to do produce the output shown above:

Print code

This code assumes the print_title function exists - read on!

Write the required print_title function to make your code  work.  As a reminder, here's the syntax of a function:

def function_name(argument_1: data_type, ..., argument_n: data_type) -> return_type:

# do things, but remember to ...

return return_value

You can use the len function to count the number of characters in each title (call this N), and then print out "-" * N to print the space character N times.

Test that your program works by printing a few things (with titles, of course), then close it down.

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