CHAPTER 12
Searching and Logic
Mystic Frog challenges you to guess the secret number! In this chapter, you’ll build a number-guessing game featuring a wise frog guarding a castle gate. The frog won’t let the player pass until they figure out the secret number. To help, Mystic Frog will reveal a range — for example, 1 to 100 — and the goal is to guess the number in as few tries as possible. Lucky for you, you’re about to learn how to code one of the smartest and fastest ways to search: binary search! This algorithm works by “squeezing the search,” cutting the list in half with each guess until it reaches the target number.
You’ll build your Mystic Frog game using skills from previous chapters like making variables and lists and using logic. You’ll add a few new twists, too, like building in error-checking to make sure the player is guessing a number in range, counting the total number of guesses, and using speech-to-text to communicate information. By the end, you’ll have a magical search game powered by computer science — and you’ll be able to breeze through any castle-guarding frog’s logic puzzle like a true coding wizard!

Brainstorm
Your binary search toy can feature any character and setting! You can also adjust the range of numbers (the low number and the high number) and even use negative numbers if you want to get really tricky. Here we go!
Start a New Project
Begin ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access