Practice Using Functions

Let’s do Exercise 17 together as a class.

Functions for Strings

Right Justify Problem

Write a function named right_justify that takes a string as a parameter and prints the string with enough leading spaces so the last letter of the string is in column 70 of the display:

>>> right_justify("Odysseus")
>>>                                                                    Odysseus

Hint: use string concatenation (+) and repetition (*). The built-in function len() will also be helpful.

Grid Problems

a) Write a function that draws a grid like the following:

+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +

b) Write a function that draws a similar grid with four rows and columns.

c) Write a function that draws a similar grid for x rows and y columns.