Pergunta de entrevista da empresa Apple

Oop question in python and make the function.