TypeError: missing 1 required positional argument in call to super.__init__()

We Are Going To Discuss About TypeError: missing 1 required positional argument in call to super.__init__(). So lets Start this Python Article.

TypeError: missing 1 required positional argument in call to super.__init__()

  1. How to solve TypeError: missing 1 required positional argument in call to super.__init__()

    Your call to the __init__ of the superclass isn't correct. You need to pass in the radius and height parameters explicitly, rather than passing in the name of the superclass.
    super().__init__(Circle)
    should be
    super().__init__(radius, height)

  2. TypeError: missing 1 required positional argument in call to super.__init__()

    Your call to the __init__ of the superclass isn't correct. You need to pass in the radius and height parameters explicitly, rather than passing in the name of the superclass.
    super().__init__(Circle)
    should be
    super().__init__(radius, height)

Solution 1

Your call to the __init__ of the superclass isn’t correct. You need to pass in the radius and height parameters explicitly, rather than passing in the name of the superclass.

super().__init__(Circle)

should be

super().__init__(radius, height)

Original Author BrokenBenchmark Of This Content

Solution 2

I recommend to you study a little bit OOP and relation between classes, because inheritance is not the case here and has no relation with the output error.

First things first and a cilynder shape is a 3d geometric form that can agregate a circle or implements another interface to a circle but is independent.

So this forms are not properly a family and should not have a link by inheritance.

See this reference for more interesting things about agregation and comosition in software development.

I implement a funcional code for you, just a refactor.

class Circle:
    def __init__(self, radius):
        self._radius = radius
        self._area = 3.14 * (self._radius ** 2)
    
    @property
    def radius(self):
        return self._radius 

    @property
    def area(self):
        return self._area
    
class Cylinder:
    def __init__(self, radius, height, circle = None):
        self._height = height
        self._circle = circle if circle else Circle(radius)
        self._volume = self._circle.area * self._height

    @property
    def heigth(self):
        return self._height 

    @property
    def volume(self):
        return self._volume

    @property
    def area(self):
        return self._circle.area
    
# radius = float(input("radius:"))
# height = float(input("height:"))
radius = 5
height = 10

circle = Circle(radius)
cylinder = Cylinder(radius, height, circle = circle)

print("circle area:", circle.radius)
print("Cylinder area:", cylinder.area)
print("Cylinder height:", cylinder.heigth)
print("Cylinder volume:", cylinder.volume)

Original Author Franz Kurt Of This Content

Solution 3

Since height is a property associated with cylinder we will put height property in the Cylinder class and the base class Circle will only have radius property.
What you could better do have like below

class Circle:
    def __init__(self, radius):
        self.radius = radius
    
class Cylinder(Circle):
    def __init__(self, radius, height):
        super().__init__(radius)
        self.height = height # It makes sense to put height in the cyclinder here 
        self.volume = 3.14 * (self.radius ** 2) * self.height
   def set_volume(self):
        print(self.volume)
    
radius = float(input("radius:"))
height = float(input("height:"))
cyl = Cylinder(radius, height)
print("Cylinder volume:", cyl.set_volume())

Original Author Rajan Chauhan Of This Content

Solution 4

#The right code I am referring

class Circle:
    def __init__(self, radius):
    self.radius = radius

class Cylinder(Circle):
    def __init__(self, radius, height):
    super().__init__(radius)
    self.height = height 
    self.volume = 3.14 * (self.radius ** 2) * self.height
    def set_volume(self):
    print("Cylinder volume:",self.volume)

radius = float(input("radius:"))
height = float(input("height:"))
cyl = Cylinder(radius, height)
cyl.set_volume()

Original Author Rajan Chauhan Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment