Chapter 7

Making Decisions

In This Chapter

arrow Using the if statement to make simple decisions

arrow Performing more advanced decision making with the if...else statement

arrow Creating multiple decision levels by nesting statements

The ability to make a decision, to take one path or another, is an essential element of performing useful work. Math gives the computer the capability to obtain useful information. Decisions make it possible to do something with the information after it’s obtained. Without the capability to make decisions, a computer would be useless. So any language you use will include the capability to make decisions in some manner. This chapter explores the techniques that Python uses to make decisions.

remember.eps Think through the process you use when making a decision. You obtain the actual value of something, compare it to a desired value, and then act accordingly. For example, when you see a signal light and see that it’s red, you compare the red light to the desired green light, decide that the light isn’t green, and then stop. Most people don’t take time to consider the process they ...

Get Beginning Programming with Python For Dummies now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.