Table of Contents

1.1 Programming (general)
1.2 Programming using Python
1.3 Basic input and output
1.4 Errors
1.5 Development environment
1.6 Computers and programs (general)
1.7 Computer tour
1.8 Language history
1.9 Why whitespace matters
1.10 Python example: Salary calculation
1.11 Additional practice: Output art

2.1 Variables and assignments
2.2 Identifiers
2.3 Objects
2.4 Numeric types: Floating-point
“2.5 Arithmetic expressions
2.6 Python expressions
2.7 Division and modulo”
2.8 Module basics
2.9 Math module
2.10 Representing text
2.11 Additional practice: Number games

3.1 String basics
3.2 List basics
3.3 Set basics
3.4 Dictionary basics
3.5 Common data types summary
3.6 Additional practice: Grade calculation
3.7 Type conversions
3.8 Binary numbers
3.9 String formatting
3.10 Additional practice: Health data

4.1 If-else branches (general)
4.2 If-else statement
4.3 More if-else
4.4 Equality and relational operators
4.5 Boolean operators and expressions
4.7 Order of evaluation”
4.6 Membership and identity operators
4.8 Code blocks and indentation
4.9 Conditional expressions
4.10 Additional practice: Tweet decoder

5.1 Loops
5.2 While loops
5.3 More while examples
5.4 Counting
5.5 For loops
5.6 Counting using the range() function
5.7 While vs. for loops
5.8 Nested loops
5.9 Developing programs incrementally
5.10 Break and continue
5.11 Loop else
5.12 Getting both index and value when looping: enumerate()
5.13 Additional practice: Dice statistics

6.1 User-defined function basics
6.2 Print functions
6.3 Dynamic typing
6.4 Reasons for defining functions
6.5 Writing mathematical functions
6.6 Function stubs
6.7 Functions with branches/loops
6.8 Functions are objects
6.9 Functions: Common errors
6.10 Scope of variables and functions
6.11 Namespaces and scope resolution
6.12 Function arguments
6.13 Keyword arguments and default parameter values
6.14 Arbitrary argument lists
6.15 Multiple function outputs
6.16 Help! Using docstrings to document functions
6.17 Engineering examples

7.1 String slicing
7.2 Advanced string formatting
7.3 String methods
7.4 Splitting and joining strings
7.5 The string format method

8.1 Lists
8.2 List methods
8.3 Iterating over a list
8.4 List games
8.5 List nesting
8.6 List slicing
8.7 Loops modifying lists
8.8 List comprehensions
8.9 Sorting lists
8.10 Command-line arguments
8.11 Additional practice: Engineering examples
8.12 Dictionaries
8.13 Dictionary methods
8.14 Iterating over a dictionary
8.15 Dictionary nesting
8.16 String formatting using dictionaries

9.1 Classes: Introduction
9.2 Classes: Grouping data
9.3 Class methods
9.4 Class and instance object types
9.5 Class example: Seat reservation system
9.6 Class constructors
9.7 Class interfaces
9.8 Class customization
9.9 More operator overloading: Classes as numeric types
9.10 Memory allocation and garbage collection

10.1 Handling exceptions using try and except
10.2 Multiple exception handlers
10.3 Raising exceptions
10.4 Exceptions with functions
10.5 Using finally to cleanup
10.6 Custom exception types

11.1 Modules
11.2 Finding modules
11.3 Importing specific names from a module
11.4 Executing modules as scripts
11.5 Reloading modules
11.6 Packages
11.7 Standard library

12.1 Reading files
12.2 Writing files
12.3 Interacting with file systems
12.4 Binary data
12.5 Command-line arguments and files
12.6 The ‘with’ statement
12.7 Comma separated values files

13.1 Derived classes
13.2 Accessing base class attributes
13.3 Overriding class methods
13.4 Is-a versus has-a relationships
13.5 Mixin classes and multiple inheritance
13.6 Testing your code: The unittest module

14.1 Recursive functions
14.2 Recursive algorithm: Search
14.3 Adding output statements for debugging
14.4 Creating a recursive function
14.5 Recursive math functions
14.6 Recursive exploration of all possibilities

15.1 Introduction to plotting and visualizing data
15.2 Styling plots
15.3 Text and annotations
15.4 Numpy
15.5 Multiple plots

16.1 Searching and algorithms
16.2 Binary search
16.3 O notation
16.4 Algorithm analysis
16.5 Sorting: Introduction
16.6 Selection sort
16.7 Insertion sort
16.8 Quicksort
16.9 Merge sort

17.1 String formatting (old)
17.2 String formatting using dictionaries
17.3 zyBooks built-in programming window

What You’ll Find In This zyBook:

More action with less text.

  • Updated to present string formatting in a consistent manner. f-strings are introduced earlier in the material and then are consistently used to format strings in code examples, activities, and labs.
  • ~600 participation activities: Questions, animations, tools
  • ~100 auto-graded programming challenge activities using built-in programming environment
  • Configurable for high schools and non-majors
  • With test banks

Instructors: Interested in evaluating this zyBook for your class? Sign up for a Free Trial and check out the first chapter of any zyBook today!

The zyBooks Approach

Less text doesn’t mean less learning.

Provides an introduction to both the principles and the practice of programming, using a subset of Python 3. This zyBook teaches programming in a unique interactive way: Animations make challenging concepts clear, learning questions engage students, tools develop intuition and skill, web-based programming windows allow practice, and web-based challenge activities allow demonstration of skill. This zyBook includes coverage of basic programming constructs (branches, loops, functions) to advanced topics such as inheritance, exceptions, and plotting.

“I have now been asked to teach Discrete Mathematics again … because of my past experience with zyBooks I agreed to teach this topic again only if I could use the zyBook again.”


Bailey Miller
CSE Ph.D., Univ. of California, Riverside, zyBooks (Former software engineer at SpaceX)