Chapter 3. Numbers and Variables: Python Does the Math

We’ve used Python to do really fun things, like make colorful pictures in just a few lines of code, but our programs have been limited. We just ran them and watched them make pictures. What if we wanted to interact with our Python programs? In this chapter, we’ll learn how to have Python ask the user’s name and even offer to do the user’s math homework!

Variables: Where We Keep Our Stuff

In Chapter 1 and Chapter 2, we used a few variables (you might remember name from our first program in Chapter 1 or x and sides from Chapter 2). Now let’s look at what variables really are and how they work.

A variable is something you want the computer to remember while your program is running. When Python “remembers” ...

Get Teach Your Kids to Code 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.