Guess the secret number and win hundred dollars. No No, that's not what we're doing. Python is a
programming language with many use cases. It can be used to build
website softwares and also games. So today we're going to build a game like this.
By using python. So in this game we need to
guess a secret number which we don't know. If you guess it correctly you will win,
but if you couldn't you might lose. This is the simplest game that you can
build with only knowing the basics of coding. Before starting, let's sketch down our plan.
So basically we're going to code two versions for this game.
User guess version and computer guess version in the user guess version.
The computer must pick a secret number and we are going to guess.
In the computer guess version its exactly the opposite.
We are going to pick a number and computer has a guest that.
But it would be boring if the guessing took so much time.
So we add maximum guess count that user can guess. For instance you will win if you could guess
the secret number without taking more guesses you have.
But if you're not. You might lose.
As I said before, in this version computer going to generate a secret number.
To do that, we are going to use something called the random module.
If you are familiar with Python, you might already know this,
but if you are not the Python random module is an inbuilt module of Python which is used
to generate random numbers. So to select a secret number,
we have to give the starting and ending values. For example, if we put start as one
and end as ten. The computer would
randomly pick a number from one to ten. So this game would be something like this.
First computer will generate a number with the support of random module without showing us.
Then you will be asked to type your guess. If it's wrong, computer will tell you
whether your guess is too low or too high. This use as a clue to find the secret number
so it would be easy for us. And then you will be asked
again to type your guess. In that case, you know
that if it's too low, the secret number would be higher than the number you guessed.
And if it's too high, it would be lower than the number you guessed.
So this will go around again and again until you find the secret number
or when you reach the guessing limit. OK, so now let's move to the second version.
Here we have to pick a number within the range.
Then computer will randomly guess a number and we have to tell the computer whether it's too high.
Too low or correct? The best thing about this is the computer will shrink down the numbers
according to what we type until it finds the secret number. Well, it can be quite confusing,
so let's try this version number two. OK, so here's a crazy idea.
Previously we did say correct, when computer guess the secret number correctly, but what if we say
the guess is incorrect even it is correct. Basically we're going to lie to computer.