Login and get codingAfter Bite 19. Write a simple property let's write a bit more advanced one.
In this Bite you are presented with a
NinjaBelt
class that keeps track of scores and Ninja Belts earned (a very real scenario). Some setup code has been provided like the_score
and_last_earned_belt
variables and the getter and setter methods that make up the property.The goal is to write a property called
score
that does the following:
- Make sure it can only be assigned an integer,
- It can not be assigned a score lower than the current score,
- It checks in
BELTS
if a new belt was earned (for example going from 49 to 50 you earn the yellow belt), if so it stores it inself._last_earned_belt
.- For each new score print a message:
- If a new badge was earned: "Congrats, you earned {score} points obtaining the PyBites Ninja {rank} Belt" (where rank is the name of the belt titlecased, e.g. White, Yellow, etc.)
- Else just the new score: "Set new score to {score}"
See the TESTS tab for more info. Good luck, have fun and keep calm and code in Python!
190 out of 193 users completed this Bite.
Will you be the 191st person to crack this Bite?
Resolution time: ~55 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 4.36 on a 1-10 difficulty scale.
» Up for a challenge? 💪