Calculator
class¶Fill ____
pieces of the Calculator
implemention in order to pass the assertions.
class Calculator:
def __init__(self, var1, ____):
self.____ = var1
self.____ = _____
def calculate_power(self):
return self.____**____.____
def calculate_sum(____, var3):
return ____.____ + ____.____ + var3
calc = Calculator(2, 3)
assert calc.calculate_power() == 8
assert calc.calculate_sum(4) == 9
StringManipulator
class¶Fill ____
pieces and create implementation for stripped_title()
.
class StringManipulator:
"""____"""
category = ____
def __init__(self, original):
self.string = ____
def reverse_words(self):
words = self.string.____
self.string = ' '.join(reversed(____))
def make_title(self):
# Create implementation for this
def get_manipulated(____):
return self._____
assert StringManipulator.__doc__ == "Docstring of StringManipulator"
assert StringManipulator.category == "Manipulator"
str_manip = StringManipulator("cOOL pyThON")
str_manip.reverse_words()
assert str_manip.get_manipulated() == "pyThON cOOL"
str_manip.make_title()
assert str_manip.get_manipulated() == "Python Cool"
Dog
class¶Create Dog
class which has the following specification:
Dog
instance has 10 units of energyDog
has a method sleep
which gives 2 units of energyDog
has a method bark
which consumes 1 unit of energyDog
has a method get_energy
which returns the amount of energy leftclass Dog:
# Your implementation here
doge = Dog()
assert doge.get_energy() == 10
doge.bark()
doge.bark()
doge.bark()
assert doge.get_energy() == 7
doge.sleep()
assert doge.get_energy() == 9
another_doge = Dog()
assert another_doge.get_energy() == 10