Section Progress
0% Complete
////vimeo.com/353425575

In this project we are going to use Python to write a program to play “Bulls and Cows,” which is a traditional game which some of you may be familiar with in a different form as “Mastermind” (the guessing game with the coloured pegs).

In order to be able to write a computer version of the game “Bulls and Cows,” it is important to be familiar with how it works. To this end, you should play the game either online or with a partner. You can find a great online version here at mathsisfun, or just play with pen and paper.

Winning the game can be a bit tricky. It may help to play a simplified version with just two digits in order to learn how it works more easily.

The rules are:

On a sheet of paper, one player writes a 4-digit secret number. The digits must all be different. The second player tries to guess their opponent’s number. The first player tells the second player the number of matches. If the matching digits are in their right positions, they are “bulls”, if they are in different positions, they are “cows”. For example:

Secret number: 4271

Opponent’s try: 1234

Answer: 1 bull and 2 cows. (The bull is “2”, the cows are “4” and “1”.)

If the second player guesses the full secret number within the designated number of turns (possibly 10), they win that round. Players then swap roles and play continues for an even number of rounds. The overall winner is the one who guesses the most secret numbers.

Make sure you understand the rules fully and have played a few times before moving on.