FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
programmingWithPythonCode/classes/shape.py at main · thomasWeise/programmingWithPythonCode · GitHub
thomasWeise
programmingWithPythonCode
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
programmingWithPythonCode
/
classes
/
shape.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
36 lines (28 loc) · 1.04 KB
Breadcrumbs
programmingWithPythonCode
/
classes
/
shape.py
Copy path
File metadata and controls
36 lines (28 loc) · 1.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
A base class for shapes defines a general interface for defining shapes.
It has no attributes, but two methods, `area` and `perimeter`, which
non-abstract subclasses must implement to return the area and perimeter
of the shapes they represent.
>>> from pytest import raises
>>> s = Shape()
>>> with raises(NotImplementedError):
... s.area()
>>> with raises(NotImplementedError):
... s.perimeter()
"""
class
Shape
:
"""A closed geometric shape has an area and a perimeter."""
def
area
(
self
)
->
int
|
float
:
"""
Get the area of this shape.
:return: the area of this shape
:raises NotImplementedError: You must overwrite this method.
"""
raise
NotImplementedError
# must be implemented by subclasses
def
perimeter
(
self
)
->
int
|
float
:
"""
Get the perimeter of this shape.
:return: the perimeter of this shape
:raises NotImplementedError: You must overwrite this method.
"""
raise
NotImplementedError
# must be implemented by subclasses
Back
|
FazBrowse Home
|
New Git URL