forked from joaks1/python-debugging
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharea_of_rectangle.py
More file actions
executable file
·56 lines (46 loc) · 1.33 KB
/
Copy patharea_of_rectangle.py
File metadata and controls
executable file
·56 lines (46 loc) · 1.33 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
#! /usr/bin/env python3
"A script for calculating the area of a rectangle."
import sys
def area_of_rectangle(height, width = None):
"""
Returns the area of a rectangle.
Parameters
----------
height : int or float
The height of the rectangle.
width : int or float
The width of the rectangle. If `None` width is assumed to be equal to
the height.
Returns
-------
int or float
The area of the rectangle
Examples
--------
>>> area_of_rectangle(7)
49
>>> area_of_rectangle (7, 2)
14
"""
if not width:
width = int(height)
import pdb; pdb.set_trace()
area = width * height
return area
if __name__ == '__main__':
if (len(sys.argv) < 2) or (len(sys.argv) > 3):
message = (
"{script_name}: Expecting one or two command-line arguments:\n"
"\tthe height of a square or the height and width of a "
"rectangle".format(script_name = sys.argv[0]))
sys.exit(message)
height = int(sys.argv[1])
width = height
if len(sys.argv) == 3:
width = int (sys.argv[2])
area = area_of_rectangle(height, width)
message = "The area of a {h} X {w} rectangle is {a}".format(
h = height,
w = width,
a = area)
print(message)