Game Development Reference
In-Depth Information
Topics Covered In This Chapter:
import
statements
Modules
Arguments
while
statements
Conditions
Blocks
Booleans
Comparison operators
The difference between
=
and
==
.
if
statements
The
break
keyword.
The
str()
and
int()
functions.
The
random.randint()
function.
The "Guess the Number" Game
We are going to make a "Guess the Number" game. In this game, the computer will think
of a random number from 1 to 20, and ask you to guess the number. You only get six
guesses, but the computer will tell you if your guess is too high or too low. If you guess the
number within six tries, you win.
This is a good game for you to start with because it uses random numbers, loops, and
input from the user in a fairly short program. As you write this game, you will learn how to
convert values to different data types (and why you would need to do this).