Ad

Use dataclasses and math module to get real Pi values.
Also fixed test cases.

Code
Diff
  • #!/usr/bin/env python3
    """
    Debugging: FixDatTrash # 2
    """
    import math
    from dataclasses import dataclass
    
    PI = math.pi
    
    @dataclass
    class Calculator:
        """A calculator class."""
    
        num: int
            
        def calculate_power(self, exp):
            """
            Calculates power of self.num.
            parameter `exp` is the exponent.
            """
            return self.num ** exp
    
        def calculate_square_root(self):
            """Calculates square root of self.num."""
            return self.num ** 0.5
    
        def calculate_cube_root(self):
            """Calculates cube root of self.num."""
            return self.num ** (1 / 3)
    
        def calculate_circumference(self):
            """
            Calculates circumference of circle.
            self.num is the diameter of the circle.
            """
            return PI * self.num
        
        def calculate_circle_area(self):
            """
            Calculates area of circle.
            self.num is the radius of the circle
            """
            return self.num ** 2 * PI
        
    • #!/usr/bin/env python3
    • """
    • Debugging: FixDatTrash # 2
    • """
    • import math
    • from dataclasses import dataclass
    • # constant:
    • PI = 3.1415926535897
    • PI = math.pi
    • @dataclass
    • class Calculator:
    • """A calculator class."""
    • def __init__(self, num):
    • """Initialize attributes."""
    • self.num = num
    • num: int
    • def calculate_power(self, exp):
    • """
    • Calculates power of self.num.
    • parameter `exp` is the exponent.
    • """
    • return self.num ** exp
    • def calculate_square_root(self):
    • """Calculates square root of self.num."""
    • return self.num ** 0.5
    • def calculate_cube_root(self):
    • """Calculates cube root of self.num."""
    • return self.num ** (1 / 3)
    • def calculate_circumference(self):
    • """
    • Calculates circumference of circle.
    • self.num is the diameter of the circle.
    • """
    • return PI * self.num
    • def calculate_circle_area(self):
    • """
    • Calculates area of circle.
    • self.num is the radius of the circle
    • """
    • return self.num ** 2 * PI