82
E X E R C I S E # 2 7 : R E C T A N G L E D R A W I N G
drawRectangle(16, 4)
→
################
################
################
################
In this exercise, you’ll
create some ASCII art, primitive graphics created from text characters.
There will be a few such exercises in this book. In this first one, your code draws a solid rectangle out
of # hashtag characters.
Exercise Description
Write a drawRectangle() function with two integer parameters: width and height. The
function doesn’t return any values but rather prints a rectangle with the given number of hashtags in
the horizontal and vertical directions.
There are no Python assert statements to check the correctness of your program. Instead, you
can visually inspect the output yourself. For example, calling drawRectangle(10, 4) should
produce the following output:
##########
##########
##########
##########
If either the width or height parameter is 0 or a negative number, 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: for loops, range(), print(), end keyword argument for print()
Dostları ilə paylaş: