-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4-print_square.txt
More file actions
executable file
·93 lines (63 loc) · 1.63 KB
/
Copy path4-print_square.txt
File metadata and controls
executable file
·93 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
============================
How to Use 4-print_square.py
============================
This module defines a square-printing function ``print_square(size)``.
Usage
=====
Squares are printed using the ``#`` character. The parameter ``size``
represents the height and width of the square.
::
>>> print_square = __import__('4-print_square').print_square
>>> print_square(1)
#
::
>>> print_square(4)
####
####
####
####
::
>>> print_square(10)
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########
If ``size`` is zero, the function prints nothing.
::
>>> print_square(0)
Invalid Sizes
=============
The parameter ``size`` must be an integer. Otherwise, a TypeError is raised.
::
>>> print_square("not an int")
Traceback (most recent call last):
TypeError: size must be an integer
::
>>> print_square(5.5)
Traceback (most recent call last):
TypeError: size must be an integer
::
>>> print_square(None)
Traceback (most recent call last):
TypeError: size must be an integer
If ``size`` is less than zero, a ValueError is raised.
::
>>> print_square(-7)
Traceback (most recent call last):
ValueError: size must be >= 0
Note that type-checking occurs before value-checking.
::
>>> print_square(-7.5)
Traceback (most recent call last):
TypeError: size must be an integer
At least one argument must be provided.
::
>>> print_square()
Traceback (most recent call last):
TypeError: print_square() missing 1 required positional argument: 'size'