Python for Kids Book: Project 3

In these posts I outline the contents of each project in my book Python For Kids For Dummies.  If you have questions or comments about the project listed in the title post them here. Any improvements will also be listed here.

What’s in Project 3

Project 3 explores a guessing game from the command line. In order to get a guessing game up and running you need to know how to receive input from the user. This project introduces the raw_input() builtin to accommodate this.

In order to tell whether a guess is correct, the computer must compare the guess to an answer – using the == operator. Further, since raw_input returns a string, I explain that strings and numbers are different and introduce the int() builtin in order to be able to compare the input with a number.

To give a player feedback, you need to determine whether the guess was higher or lower than the desired number. The operators > and < are introduced to address this. The if conditional along with the variants elif and else are introduced to be able to structure the feedback given to a player.

To choose a number at random you learn about import, the random module and random.randint.

The while structure introduced in Project 2 is used to allow the player to make repeated guesses of the answer. This is coupled with the break keyword to exit the loop one the correct number is guessed.

In the course of introducing the ==, > and < operators, I also give an overview of more common operators used in Python (at Table 3-1).  After introducing the operators I discuss why division in Python is a special case, how to recognize problems with division and how to get a decimal answer if that’s what you’re after.

4 Responses to Python for Kids Book: Project 3

  1. floop says:

    Why did Amazon jump from the book being available today to a September release date?

Leave a Reply to floop Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: