85
E X E R C I S E # 2 8 : B O R D E R D R A W I N G
drawBorder(16, 4)
→
+--------------+
| |
| |
+--------------+
Similar to the solid, filled-in ASCII art rectangles our code generated in Exercise #27, ―Rectangle
Drawing,‖ this exercise draws only the border of a rectangle. The + plus character is used for the
corners, the - dash character for horizontal lines, and the | pipe character for vertical lines. (This is
the similar style as the lines in Exercise #25’s multiplication table.
Exercise Description
Write a drawBorder() function with parameters width and height. The function draws the
border of a rectangle with the given integer sizes. There are no Python assert statements to check
the correctness of your program. Instead, you can visually inspect the output yourself. For example,
calling drawBorder(16, 4) would output the following:
+--------------+
| |
| |
+--------------+
The interior of the rectangle requires printing spaces. The sizes given include the space required
for the corners. If the width or height parameter is less than 2, the function should print nothing.
Try to write a solution based on the information in this description. If you still
have trouble
solving this exercise,
read the Solution Design and Special Cases and Gotchas sections for
additional hints.
Prerequisite concepts: Boolean operators, strings, string concatenation,
string replication, for
loops, range()
Dostları ilə paylaş: