Return To CS 110 Home

Colour Theme   Font Size Options
 
   
   
   
Binary Guessing Game

Binary Guessing Game


Video Summary: https://youtu.be/FDGCnDuAC4Y


A party trick for computer scientists is to use the fact that average people don't understand binary numbers to guess a number they pick. It could look something like this:

Pick a number between 0 and 8
Is your number in this list:
1, 3, 5, 7
n
Is your number in this list:
2, 3, 6, 7
y
Is your number in this list:
4, 5, 6, 7
y
Your number is 6

The trick is quite simple. Each list represents a bit in a three bit number. If the number is in the first list, add one. If it is on the second list, add 2. If it is on the third, add 4.

Your goal for this exercise is to use if statements to recreate the binary guessing game, similar to the output shown above. Assume your user will always enter y or n.

Solution