Puzzle 2 – create an AI bot to guess a number

The Algorithm

Here's my Scratch program showing a way of coding a linear search algorithm so that the computer guesses a number that you're thinking of.

This is a very simple form of Artificial Intelligence (AI) I suppose. The computer's going to be doing the hard work this time.

This isn't too tricky. You should be able to figure out how it works.

Scratch program image

We can convert this program into Python, which is a much more powerful programming language.

THEORY: the program uses sequence and repetition. Sequence is just getting instructions in the right order.
It also uses three variables called guesses, number, and answer.

It's pretty much one Scratch block equals one line of Python, although there are a couple of things we need to do a little bit differently in Python.

We'll divide the Scratch program into three parts to make it easier to handle.