Ad

changed calculate_power to use python's built in exponentiation.

Code
Diff
  • #!/usr/bin/env python3
    """
    Debugging: FixDatTrash # 2
    """
    
    # constant:
    PI = 3.1415926535897
    
    
    class Calculator:
        """A calculator class."""
    
        def __init__(self, num):
            """Initialize attributes."""
            self.num = num
    
        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
        
    • #!/usr/bin/env python3
    • """
    • Debugging: FixDatTrash # 2
    • """
    • # constant:
    • PI = 3.1415926535897
    • class Calculator:
    • """A calculator class."""
    • def __init__(self, num):
    • """Initialize attributes."""
    • self.num = num
    • def calculate_power(self, exp):
    • """
    • Calculates power of self.num.
    • parameter `exp` is the exponent.
    • """
    • result = 1
    • for exp in range(exp, 0, -1):
    • result *= self.num
    • return result
    • 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