O'Reilly logo

Head First Learn to Code by Eric Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. 2 simple values, variables, and types: Know Your Value

Image

Computers really only do two things well: store values and perform operations on those values. You might think they’re doing a whole lot more, as you send texts, shop online, use Photoshop, or rely on your phone to navigate in your car; however, everything computers do can be broken down into simple operations that are performed on simple values. Now, part of computational thinking is learning to use these operations and values to build something that is much more sophisticated, complex, and meaningful—and we’re going to get to that. First, though, we’re going to take a look at what these values are, the operations you can perform on them, and just what role variables play in all this.

Coding the Dog Age Calculator

You didn’t think we were going to take you through 50 pages of Python specifications on values and operations before writing some real code, did you? Of course not—we’ve got real work to do!

Up next, the Dog Age Calculator. You already know what the calculator does: you enter a dog’s chronological age and the calculator tells you the dog’s age in relative human years. To perform that calcuation you simply multiply the dog’s chronological age by the number 7. Or, is it that simple? We shall see...

But where do we even start? Do we just start trying to write some code? Well, remember the concept of pseudocode, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required