From a2289833e59c852b79532b47aebf17a33b95cb9c Mon Sep 17 00:00:00 2001 From: Zhongheng Liu Date: Thu, 6 Feb 2025 07:47:50 +0000 Subject: oop --- oop/oop.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 oop/oop.py (limited to 'oop/oop.py') 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 -- cgit