Computer scienceProgramming languagesPythonObject-oriented programmingMethods

Methods and attributes

Cone

Report a typo

In what order should an object of the class Cone call its methods so that everything is calculated and displayed correctly?

class Cone:
    PI = 3.14

    def __init__(self, radius, height):
        self.radius = radius
        self.height = height
        self.base_area = None
        self.slant_height = None
        self.surface_area = None
        self.volume = None 

    def get_base_area(self):
        self.base_area = self.PI * (self.radius ** 2)

    def get_parameters(self):
        self.slant_height = math.sqrt((self.radius ** 2) + (self.height ** 2))
        self.surface_area = self.PI * self.radius * self.slant_height
        info = "Area of the base = {}\n".format(self.base_area)
        info += "Volume = {}\n".format(self.volume)
        info += "Surface area = {}".format(self.surface_area)
        print(info)
        
    def get_volume(self):
        self.volume = (1/3) * self.base_area * self.height
Put the items in the correct order
get_parameters
get_volume
get_base_area
___

Create a free account to access the full topic