We use Python 3.6

go back Level: Advanced (img: AV / score: 4) level Bite 42. Number Guessing Game Class

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

In this Bite you implement a Game class to perform a number guessing game. It lets a user do a max of 5 guesses of a secret number between 1 and 20 randomly defined by the class.

Note you have to account for invalid inputs: raise a ValueError if a user hits Enter (nothing entered), a non-numeric value, a number that is not in the 1-20 range, or guesses the same number again. See the template code below ... (Advanced Bite, not giving away too much!)

The tests run through a lose scenario as well. Note they mock out the input builtin to test this. And you will be tested on stdout too so use print statements in addition to return values. Here is how the program would work from the command line.

Good luck, have fun and keep calm and code in Python!

Github login button