Login and get codingIn 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 ... (AdvancedBite, 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 onstdouttoo so useGuessed it (note wrong input does not count towards number of guesses):

$ python guess.py Guess a number between 1 and 20: Please enter a number Guess a number between 1 and 20: string Should be a number Guess a number between 1 and 20: 5 5 is too low Guess a number between 1 and 20: 15 15 is too high Guess a number between 1 and 20: 10 10 is too high Guess a number between 1 and 20: 8 8 is too high Guess a number between 1 and 20: 6 6 is correct! It took you 5 guessesGuessed it - another example:

$ python guess.py Guess a number between 1 and 20: -1 Number not in range Guess a number between 1 and 20: Please enter a number Guess a number between 1 and 20: 8 8 is too high Guess a number between 1 and 20: 10 10 is too high Guess a number between 1 and 20: 4 4 is correct! It took you 3 guessesDid not guess it:

$ python guess.py Guess a number between 1 and 20: 9 9 is too low Guess a number between 1 and 20: 8 8 is too low Guess a number between 1 and 20: 7 7 is too low Guess a number between 1 and 20: 6 6 is too low Guess a number between 1 and 20: 5 5 is too low Guessed 5 times, answer was 16Good luck, have fun and keep calm and code in Python!

Metrics »

135 out of 145 users completed this Bite.

Will you be Pythonista #136 to crack this Bite?

Resolution time: ~85 min. (avg. submissions of 5-240 min.)

Pythonistas rate this Bite 6.11 on a 1-10 difficulty scale.

» Up for a challenge? 💪

Ask for Help