I'm a bit of a beginner with OOP and have been trying to teach myself some of its concepts using Python3. However, I have gotten stuck with inheritance. This is my source code:
#! /usr/bin/env python3
class TwoD:
def __init__(self, height, width):
self.h = height
self.w = width
def perimeter(self, height, width):
return 2 * (height + width)
def area(self, height, width):
return height * width
class Cuboid(TwoD):
def __init__(self, height, width, depth):
self.d = depth
def volume(self, height, width, depth):
return height * width * depth
x = Cuboid(3, 4, 5)
print(x.volume())
print(x.perimeter())
print(x.area())
The error I get when I run it is below. It reads as though I need to add arguments to volume, but doesn't x provide it with the required variables?
Traceback (most recent call last):
File "./Class.py", line 19, in <module>
print(x.volume())
TypeError: volume() missing 3 required positional arguments: 'height', 'width', and 'depth'
So could someone please let me know what I am doing wrong. I'm sure it is something silly. Also, could someone please explain how I would go about using multiple inheritance in Python3?
Thanks in advance