We use Python 3.6

go back Level: Intermediate (img: IM / score: 3) level Bite 71. Keep state in a class + make its instance callable

20 out of 20 users completed this Bite ...
Will you be Pythonista #21 to crack this Bite?
Average Bite difficulty 1-10 rating: 5.5
» Up for a challenge? 💪

In this Bite you write a small class to keep track of the max score in a game. It keeps an internal scores list and when called as a function it receives a new score and returns the max score.

So calling it like this:

record = RecordScore()
print(record(10))
print(record(9))
print(record(11))
print(record(7))

.. would give the following outputs (11 becomes the new max score):

10
10
11
11

To achieve this implement the __call__ dunder (special) method on the RecordScore class. Good luck!

Github login button