Computer Science Lesson Outline: The Guessing GamesteemCreated with Sketch.

in #teaching8 years ago (edited)

Learning Concepts:
Algorithms, Loops, Boolean Logic, Variables, User Input, Algorithm Complexity, Simple AI

Lesson:
Start by introducing the childhood game of guessing a number. Give them a range, perhaps start with 1 to 100 and have them guess, giving them feedback of higher or lower. Most likely there will be some students who will already hit upon the optimal solution which is essentially a binary search algorithm. To reinforce this you can go "hard" on them, and do 1 to 1000 (or higher) and show them how it is not actually that much harder. If you want to go into Big O complexity, you could touch on the basic O(n) solution and the improved O(log n) solution.

Exercise:
Then you will give the student an assignment in the language of your class to write an interface to play the game. The system will pick a random number between a given range and then allow for user input to guess a number. If they get it right, tell the user they won and end the game. If they do not guess the right number, give feedback whether the number was too low or high. This game will require the students to user variables (storing the random number), loops (repeated guesses), gathering user input and boolean logic using '=','<'' and '>'.

Extension:
For those kids that are finished quickly, you can let them write a bot that will play the game for them. Simple bots will just guess in order or randomly. More advanced bots will use a min and max value, guess the average of the two then adjust the min or max based on whether the previous guess was low or high.

Coin Marketplace

STEEM 0.13
TRX 0.34
JST 0.033
BTC 114321.56
ETH 4283.90
USDT 1.00
SBD 0.86