A class that can be called.
class greeting:
def __init__(self, name: str, formal: bool = False):
self.name = name
self.formal = formal
def __call__(self) -> str:
if self.formal: return f'Hello, Sir {self.name}.'
else: return f'Hello, {self.name}!'
g1 = greeting('John')
g2 = greeting('Churchill', True)
print(g1()) # 'Hello, John!'
print(g2()) # 'Hello, Sir Churchill.'
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(greeting('John')(), 'Hello, John!')
test.assert_equals(greeting('Churchill', True)(), 'Hello, Sir Churchill.')