Added Python files from our 1st classes
This commit is contained in:
parent
68b370241f
commit
508af05677
11
python/Circle.py
Normal file
11
python/Circle.py
Normal file
@ -0,0 +1,11 @@
|
||||
from Figure import Figure
|
||||
|
||||
|
||||
class Circle(Figure):
|
||||
_r = None
|
||||
|
||||
def setr(self, r):
|
||||
self._r = r
|
||||
|
||||
def area(self):
|
||||
print("area = " + str(3.14 * self._r**2))
|
4
python/Figure.py
Normal file
4
python/Figure.py
Normal file
@ -0,0 +1,4 @@
|
||||
class Figure:
|
||||
|
||||
def area(self):
|
||||
print("Not implemented")
|
13
python/Rectangle.py
Normal file
13
python/Rectangle.py
Normal file
@ -0,0 +1,13 @@
|
||||
from Figure import Figure
|
||||
from Square import Square
|
||||
|
||||
|
||||
class Rectangle(Square):
|
||||
|
||||
_y = None
|
||||
|
||||
def sety(self, y):
|
||||
self._y = y
|
||||
|
||||
def area(self):
|
||||
print("area = " + str(self._x * self._y))
|
12
python/Square.py
Normal file
12
python/Square.py
Normal file
@ -0,0 +1,12 @@
|
||||
from Figure import Figure
|
||||
|
||||
|
||||
class Square(Figure):
|
||||
|
||||
_x = None
|
||||
|
||||
def setx(self, x):
|
||||
self._x = x
|
||||
|
||||
def area(self):
|
||||
print("area = " + str(self._x * self._x))
|
15
python/main.py
Normal file
15
python/main.py
Normal file
@ -0,0 +1,15 @@
|
||||
from Circle import Circle
|
||||
from Figure import Figure
|
||||
from Rectangle import Rectangle
|
||||
|
||||
if __name__ == '__main__':
|
||||
r = Rectangle()
|
||||
r.setx(4)
|
||||
r.sety(8)
|
||||
r.area()
|
||||
|
||||
c = Circle()
|
||||
c.setr(1)
|
||||
c.area()
|
||||
|
||||
print('Finished')
|
Loading…
Reference in New Issue
Block a user