@extends('template') @section('title') Lab 6: Hints for Hi/Lo game @stop @section('head') @stop @section('content') [← Return to Hi/Lo instructions](while-loops) # Lab 6: 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). ```xml 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. 4. Write your `if` statement to cover these cases: * If the guess is higher than the secret number, print `Too high` * If the guess is lower than the secret number, print `Too low` * If the guess is the same as the secret number, print `Wahoo` (or your fave celebratory expression) 5. 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). 6. Now think about getting the loop to stop when you want it to. Hint: use `break`. 7. Add the print statement at the appropriate place when the user has run out of guesses and reveal the secret number. 8. If the user guesses correctly, make sure you print the number of guesses after your wahoo message.
[← Return to Hi/Lo instructions](while-loops) @stop