Hints for Hi/Lo game

  1. Inside hiLo() generate a random number between 1 and 50, inclusive, and assign it to a variable. Test this and make sure it works before proceeding.

  2. Write a while loop. When will your loop stop executing? Use that to write your boolean expression.

  3. Experiment with the provided getUsersGuess() to make sure you understand how it works. The function returns the integer that the user guesses (and assumes that the user types in a positive number).
In [17]: getUsersGuess()

Take a guess: 5
Out[17]: 5

In [18]: getUsersGuess()

Take a guess: 10
Out[17]: 10

In hiLo(), inside your while loop, assign the user's guess to a variable.

  1. Write your if statement to cover these cases:
  1. Run your code to see if the condition works. Run it a bunch of times to make sure it works in different cases. Don't worry about the game ending correctly (yet).

  2. Now think about getting the loop to stop when you want it to. Hint: use break.

  3. Add the print statement at the appropriate place when the user has run out of guesses and reveal the secret number.

  4. If the user guesses correctly, make sure you print the number of guesses after your wahoo message.


← Return to Hi/Lo instructions