I'm working on a shapes implementation in Python 3.10.12 and encountering a TypeError when trying to create a Circle object. Here's the relevant code:
Here is the code for shape.py
class Shape: def __init__(self, name): self.name = name def perimeter(self): raise NotImplementedError("perimeter") def area(self): raise NotImplementedError("area")class Square(Shape): def __init__(self, name, side): super().__init__(name) self.side = side def perimeter(self): return 4 * self.side def area(self): return self.side**2class Circle(Shape): def __init__(self, name, radius): super().__init__(name) self.radius = radius def perimeter(self): return 2 * math.pi * self.radius def area(self): return math.pi * self.radius**2Here is the code for test.py
from shape import *examples = [Square("sq", 3), Circle("ci", 2)] # Error occurs herefor thing in examples: n = thing.name p = thing.perimeter() a = thing.area() print(f"{n} has perimeter {p} and area {a}")The error message states:
TypeError: Circle() takes 1 positional argument but 2 were givenIt states that erroe is in line 3 of test.py
Additional Information:
- Course: Learning Software Design by Example (third-bit)
- Problem link: https://third-bit.com/sdxpy/oop/: https://third-bit.com/sdxpy/oop/
Thank you in advance for your assistance!
dthedev@dip:~/python$ python3 test.pyTraceback (most recent call last): File "/home/dthedev/python/test.py", line 3, in <module> examples = [Square("sq", 3), Circle("ci", 2)]TypeError: Circle() takes 1 positional argument but 2 were givendthedev@dip:~/python$