avatar Bite 71. Keep state in a class + make its instance callable

In this Bite you write a small class to keep track of the max score in a game. When called as a function it receives a new score and returns the max score. Note it should work with negative numbers as well.

This is how it should work:

  >>> from record import RecordScore

  >>> record = RecordScore()
  >>> print(record(10))
  >>> print(record(9))
  >>> print(record(11))  # new max

  >>> record = RecordScore()
  >>> print(record(-5))
  >>> print(record(-10))
  >>> print(record(-2))  # new max

Use the __call__ dunder ("special") method to make the RecordScore class callable.

Good luck and keep calm and code in Python!

Login and get coding
go back Intermediate level
Bitecoin 3X

Will you be Pythonista #370 to crack this Bite?
Resolution time: ~27 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 2.67 on a 1-10 difficulty scale.
» You can do it! 😌

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help