Define a score enum and customize it adding methods
Level: Intermediate (score: 3)
Starting Python 3.4 there is support for enumerations (not to confuse with the enumerate
builtin). You can define a class that inherits from Enum
.
In this Bite we have some constants that are related: the scores we provide for our Bites depending the level and if cheated. As these variables relate they are an ideal candidate to be refactored into an Enum
. But that would not be much of a Bite, right? So we added two requirements:
- Add a
__str__
method so each member would print like this:BEGINNER => 👍👍
, where BEGINNER is the level and the number of thumbs ups the amount of points. - Write a
classmethod
calledaverage
that returns an average of the scores in theEnum
.
See the TESTS tab for more info. You might want to read the Enum docs to see how you can pull this off. We hope it clicks and you find joy coding this one, and of course that you earn your full 👍👍👍 for this INTERMEDIATE Bite. Good luck and have fun!