diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-02-06 09:50:00 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-02-06 09:50:00 +0200 |
commit | 5e297261b05ed2c3feef0a892fc47e5fa06dbc4c (patch) | |
tree | 2ae9783dd2fc0efe42bc31e52e9984157c49d8a0 /oop/oop.py | |
parent | 6fdd8b6737ed7e018900ceaf2fcec3d926839912 (diff) | |
parent | a2289833e59c852b79532b47aebf17a33b95cb9c (diff) | |
download | cs-y13-5e297261b05ed2c3feef0a892fc47e5fa06dbc4c.tar.gz cs-y13-5e297261b05ed2c3feef0a892fc47e5fa06dbc4c.tar.bz2 cs-y13-5e297261b05ed2c3feef0a892fc47e5fa06dbc4c.zip |
Merge branch 'main' of github.com:stvnliu/cs-y13
Diffstat (limited to 'oop/oop.py')
-rw-r--r-- | oop/oop.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/oop/oop.py b/oop/oop.py new file mode 100644 index 0000000..4ef15d7 --- /dev/null +++ b/oop/oop.py @@ -0,0 +1,32 @@ +import math
+class shape:
+ def __init__(self):
+ pass
+ def area(self):
+ pass
+class circle(shape):
+ def __init__(self, r):
+ shape.__init__(self)
+ self._radius = r
+ def area(self):
+ return self._radius * self._radius * math.pi
+class rectangle(shape):
+ def __init__(self, side1, side2):
+ shape.__init__(self)
+ self._a = side1
+ self._b = side2
+ def area(self):
+ return self._a * self._b
+class square(shape):
+ def __init__(self, side):
+ shape.__init__(self)
+ self._side = side
+ def area(self):
+ return self._side ** 2
+
+sq = square(4)
+cir = circle(7)
+rect = rectangle(3,6)
+print(sq.area())
+print(cir.area())
+print(rect.area())
\ No newline at end of file |