Chapter 9

Make a Guessing Game with Python

Chapter 8 introduces the Python programming language. This chapter explains how to make a simple number guessing game for one player. The player thinks of a number between 1 and 10. Your code guesses the number.

Sounds simple, right?

Not so fast. You have to think about everything that can happen in the game. And you also have to discover more about Python.

image

Think about Code

Does having to think about code mean you’re a terrible programmer?

No!

It’s good. It means you have to think about what you’re doing. Good programmers do a lot of thinking before they start writing and typing code. They start by breaking a big and complicated problem into small steps. Then they work through the steps.

Good programmers have to learn new tricks all the time. You might think developers already know everything they need to know.

It would be cool if they did. But that’s not what happens.

Software developers have to learn new things all the time. Sometimes this means looking up how to do things in a new language — like Python. Sometimes it means finding out whether someone else has invented a clever answer for a problem. And sometimes it means looking at the code and projects that other developers are working on to see whether you can learn anything from them.

So not knowing where to start is normal. It’s how most projects begin.

Work out what you ...

Get Raspberry Pi For Kids For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.