CHAPTER 3

Imperative Programming

3.1 Python Programs

3.2 Execution Control Structures

3.3 User-Defined Functions

3.4 Python Variables and Assignments

3.5 Parameter Passing

3.6 Case Study: Automating Turtle Graphics

Chapter Summary

Solutions to Practice Problems

Exercises

Problems

IN THIS CHAPTER, we discuss how to develop Python programs. A Python program is a sequence of Python statements that are executed in order. To achieve different program behavior depending on a condition, we introduce a few decision and iteration control flow structures that control whether and how many times particular statements are executed.

As we develop more code, we will note that, often, the same group of Python statements is used repeatedly and implements a task that can be described abstractly. Python gives developers the ability to wrap code into functions so the code can be executed with just one function call. One benefit of functions is code reuse. Another is that they simplify the developer's job by (1) hiding the code implementing the function from the developer and (2) making explicit the abstract task achieved by the code. In the chapter case study, we continue the use of turtle graphics to illustrate code reuse, information hiding, and functional abstraction.

The concepts covered in this chapter are fundamental programming language concepts, not just Python concepts. This chapter also introduces the process of breaking down problems into steps that can be described computationally using ...

Get Introduction to Computing Using Python: An Application Development Focus 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.