You’ve hidden a mysterious item under one of a row of rocks, hoping to keep it safe from prying eyes. But Sasquatch has caught wind of your secret and is determined to find it! To outsmart Sasquatch, you’ve left the item under a rock at a random position between 1 and 100. Sasquatch, being clever, will try to guess which rock hides your treasure.
Sasquatch playing playing a guessing game with a human. Image created by Copilot using Dall-E3.
Write a Python program where Sasquatch (the computer) tries to guess which rock your item is hidden under. You (the user) will give feedback after each guess:
If Sasquatch’s guess is too high, respond with "grunt."
If the guess is too low, respond with "growl."
When Sasquatch guesses the correct rock, respond with "laugh."
Here’s what students need to know to complete the assignment:
Cave Number Selection: Start the program by prompting the user to think of a cave number between 1 and 100. Tell the user to hit the Enter key when ready (notice, the user isn't typing the number or providing it to the computer in any way)
Track Limits: To make Sasquatch’s search more efficient, it needsto track the lowest and highest rock positions they’ve narrowed down so far. Start with a range from 1 to 100, but each time a guess is "too high" or "too low," Sasquatch should update the range accordingly. For example:
If Sasquatch guesses rock 50 and you respond with "growl" (too low), Sasquatch should adjust the lower limit to 51. The next guess should be between 51 and 100.
If Sasquatch guesses rock 90 and you respond with "grunt" (too high), Sasquatch should set the upper limit to 89. The next guess should be between 51 & 89.
Smart vs. Intelligently-Random - You have two choices for Sasquatch’s strategy, you need to choose one of these to program:
Smart - Sasquatch always guesses the middle number in the adjusted range (e.g., if the range is 51 to 89, the guess would be 70).
Intelligently Random - Sasquatch picks a random number within the adjusted limits (e.g. if the range is 51-89, the guess could be 53).
Important: Sasquatch should not pick "stupid" guesses (e.g., if he knows the number is higher than 50, he shouldn’t guess anything ≤50 again).
Think of which rock you hid your treasure under for Sasquatch to find (1-100). Hit enter when ready.
Sasquatch guesses rock 50.
You respond: growl.
Sasquatch now knows the item is between rocks 51 and 100.
Sasquatch guesses rock 75.
You respond: grunt.
Sasquatch now knows the item is between rocks 51 and 74.
Sasquatch guesses rock 63.
You respond: laugh.
Sasquatch has found the hidden item!