Can Python Guess Your Number in 7 Tries? | Binary Search for Beginners
Description: Pick a secret number from 1 to 100. Can you make Python take an eighth guess? After each guess, tell it “higher,” “lower,” or “correct,” and see how long your number survives.
In this beginner Python code-along, we’ll build the game from scratch, play a round, and test it against all 100 possible secrets. You’ll see why seven guesses are enough, why six can fall short, and how the same binary search helps you find a vinyl record by its catalogue number.
To code along, you’ll need Python 3, a text editor, and a terminal. You can also play the guessing game with just a pen and paper.
Chapters
00:00 The seven-guess bet
01:18 Why start in the middle?
03:02 Write Python’s first guess
05:09 Let the player answer
07:24 Build a playable round
10:13 Play the round that takes all seven guesses
12:10 Break the game with just two numbers
14:19 Test all 100 secrets
17:00 Why six guesses can’t guarantee a win
19:15 Search a crate of vinyl records
21:22 Your rematch
What number did you pick, and how many guesses did Python need? Leave your score in the comments. Subscribe to Learn Coding Fast for more beginner Python projects. Close description
In this beginner Python code-along, we’ll build the game from scratch, play a round, and test it against all 100 possible secrets. You’ll see why seven guesses are enough, why six can fall short, and how the same binary search helps you find a vinyl record by its catalogue number.
To code along, you’ll need Python 3, a text editor, and a terminal. You can also play the guessing game with just a pen and paper.
Chapters
00:00 The seven-guess bet
01:18 Why start in the middle?
03:02 Write Python’s first guess
05:09 Let the player answer
07:24 Build a playable round
10:13 Play the round that takes all seven guesses
12:10 Break the game with just two numbers
14:19 Test all 100 secrets
17:00 Why six guesses can’t guarantee a win
19:15 Search a crate of vinyl records
21:22 Your rematch
What number did you pick, and how many guesses did Python need? Leave your score in the comments. Subscribe to Learn Coding Fast for more beginner Python projects. Close description
