0

I am just trying to get a program that receives a point from one class, and then in another class, it uses that point as the center of the circle. I imagine this is simple but I don't know how to do it.

class Point:
     def __init__(self, x, y):
        self.x = x
        self.y = y

class Circle(Point):
     def circle(self, center, radius):
        Point.x = center
        Point.y = center
        self.radius = radius

2 Answers 2

3

You shouldn't subclass Point for your Circle class, it doesn't make much sense as they are two completely different things. Instead you can take a Point as the center of your circle and pass it into the Circle class in the init

class Circle(object):
    def __init__(self, center: Point, radius):
        self.center = center
        self.radius = radius
Sign up to request clarification or add additional context in comments.

Comments

0

The way you are doing it, with inheritance, is a bit confusing.

2 options are avalaible.

First : As mention by @Iain Shelvington, you could use the Point class as a member of your Circle class.

Second : If you really want to sub class it / inherit from the point in your circle, you have to super.init() it.

class Circle(Point):
    def __init__(self, x, y, radius):
        super().__init__(x, y) # which is the same as creating a self.x and y for Circle
        self.radius = radius

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.