Problem Solving with Python
Author(s): Margaret Burke
Edition: 1
Copyright: 2018
Pages: 276
The field of computer sciences is broad, deep, and continually growing, and impacts nearly every quarter of our modern lives. Computer scientists, therefore, need to be lifelong learners.
Problem Solving with Python takes an explicit problem-solving approach to the introduction of computer programming and computational thinking, emphasizing the programmer’s role in problem definition, expressing, evaluating, and implementing solutions, and evaluating results.
Designed to lay the groundwork for further study in computer science, Problem Solving with Python:
- Encourages curiosity and guides exploration, experimentation, and the meaningful evaluation of results.
- Uses turtle graphics and interesting computation problems in the Python 3 programming language to introduce fundamental imperative programming constructs and patterns.
- Includes chapters on input-processing-output programs, conditional and iterative structures, functions, recursion, file processing, lists and strings, and contains an introduction to secure programming.
- Presents programming constructs as tools for the solution of classes of problems, using the problems as motivation for mastering the tools.
- Try This and Challenge Accepted! problem sections are suitable for laboratory exercises, starting points for classroom discussion, or to help the reader develop the habits of mind they will need for success as a computer programmer.
1. Getting started with Python
1.1 Problem solving
1.2 Let’s get started!
1.3 Meet the turtle
1.4 Designing solutions
1.5 When things go wrong
1.6 Challenge accepted!
2. Input, processing, output programs
2.1 Your programming tool kit
2.2 Literals and data types
2.3 Variables
2.4 Variable names and keywords
2.5 Constants
2.6 Evaluating expressions
2.7 Operators and operands
2.8 Order of operations
2.9 Math functions and mathematical expressions in Python
2.10 Input and type conversion functions
2.11 Formatting output
2.12 Comments
2.13 Using your tool kit
2.14 Challenge accepted!
3. Logic and conditional statements
3.1 Changing the flow
3.2 Relational operators and Boolean expressions
3.3 Boolean operators and short-circuiting
3.4 Checking ranges
3.5 Boolean variables
3.6 What else?
3.7 Complementing logical expressions
3.8 Testing assumptions with assert statements
3.9 Series if statements
3.10 Nested if statements
3.11 Desk checking and debugging conditional statements
3.12 Data representation
3.13 The random library
3.14 Challenge accepted!
4. Loops and files
4.1 Finding repetition in a problem
4.2 Desk-checking loops
4.3 The loop control variable
4.4 Loop design errors
4.5 Augmented assignment operators
4.6 Loop patterns
4.7 Input validation loops
4.7 Sentinel-controlled loops
4.8 File processing
4.9 Counting loops and ranges
4.10 Nested loops
4.11 Finding repetition in a problem (again)
4.12 Challenge accepted!
5. Functions
5.1 Defining functions
5.2 Functional decomposition
5.3 Flow of control
5.4 Parameters
5.5 Returning values
5.6 Input–processing–output (IPO) charts and structure charts
5.7 Code blocks, namespaces, and scope
5.8 The math module, revisited
5.9 Input validation functions
5.10 Problem-solving with functions
5.11 Challenge accepted!
6. Lists
6.1 Collections and indexing
6.2 Loops and lists
6.3 Slicing, concatenating, and copying
6.4 Operations on lists
6.5 Lists and functions
6.6 Lists and files
6.7 Two-dimensional lists
6.8 Parallel lists and records
6.9 Strings, revisited
6.10 Problem-solving with lists
6.11 Challenge accepted!
7. Supplementary chapter: Number Systems
7.1 What is a number base?
7.2 Binary numbers
7.3 Hexadecimal numbers
7.4 Conversions
7.5 Seven-bit ASCII, 8-bit ASCII, Unicode: How many digits do we need?
8. Supplementary chapter: Introduction to security-conscious coding
8.1 What you already know
8.2 What do malicious actors do?
8.3 Know your data
8.4 Validating type with exception handling
8.5 Restricting input size with files
8.6 Validating input with string functions and regular expressions
9. Supplementary chapter: Recursion
9.1 Recursive problems
9.2 The call stack
9.3 Designing recursive solutions
References
Index
The field of computer sciences is broad, deep, and continually growing, and impacts nearly every quarter of our modern lives. Computer scientists, therefore, need to be lifelong learners.
Problem Solving with Python takes an explicit problem-solving approach to the introduction of computer programming and computational thinking, emphasizing the programmer’s role in problem definition, expressing, evaluating, and implementing solutions, and evaluating results.
Designed to lay the groundwork for further study in computer science, Problem Solving with Python:
- Encourages curiosity and guides exploration, experimentation, and the meaningful evaluation of results.
- Uses turtle graphics and interesting computation problems in the Python 3 programming language to introduce fundamental imperative programming constructs and patterns.
- Includes chapters on input-processing-output programs, conditional and iterative structures, functions, recursion, file processing, lists and strings, and contains an introduction to secure programming.
- Presents programming constructs as tools for the solution of classes of problems, using the problems as motivation for mastering the tools.
- Try This and Challenge Accepted! problem sections are suitable for laboratory exercises, starting points for classroom discussion, or to help the reader develop the habits of mind they will need for success as a computer programmer.
1. Getting started with Python
1.1 Problem solving
1.2 Let’s get started!
1.3 Meet the turtle
1.4 Designing solutions
1.5 When things go wrong
1.6 Challenge accepted!
2. Input, processing, output programs
2.1 Your programming tool kit
2.2 Literals and data types
2.3 Variables
2.4 Variable names and keywords
2.5 Constants
2.6 Evaluating expressions
2.7 Operators and operands
2.8 Order of operations
2.9 Math functions and mathematical expressions in Python
2.10 Input and type conversion functions
2.11 Formatting output
2.12 Comments
2.13 Using your tool kit
2.14 Challenge accepted!
3. Logic and conditional statements
3.1 Changing the flow
3.2 Relational operators and Boolean expressions
3.3 Boolean operators and short-circuiting
3.4 Checking ranges
3.5 Boolean variables
3.6 What else?
3.7 Complementing logical expressions
3.8 Testing assumptions with assert statements
3.9 Series if statements
3.10 Nested if statements
3.11 Desk checking and debugging conditional statements
3.12 Data representation
3.13 The random library
3.14 Challenge accepted!
4. Loops and files
4.1 Finding repetition in a problem
4.2 Desk-checking loops
4.3 The loop control variable
4.4 Loop design errors
4.5 Augmented assignment operators
4.6 Loop patterns
4.7 Input validation loops
4.7 Sentinel-controlled loops
4.8 File processing
4.9 Counting loops and ranges
4.10 Nested loops
4.11 Finding repetition in a problem (again)
4.12 Challenge accepted!
5. Functions
5.1 Defining functions
5.2 Functional decomposition
5.3 Flow of control
5.4 Parameters
5.5 Returning values
5.6 Input–processing–output (IPO) charts and structure charts
5.7 Code blocks, namespaces, and scope
5.8 The math module, revisited
5.9 Input validation functions
5.10 Problem-solving with functions
5.11 Challenge accepted!
6. Lists
6.1 Collections and indexing
6.2 Loops and lists
6.3 Slicing, concatenating, and copying
6.4 Operations on lists
6.5 Lists and functions
6.6 Lists and files
6.7 Two-dimensional lists
6.8 Parallel lists and records
6.9 Strings, revisited
6.10 Problem-solving with lists
6.11 Challenge accepted!
7. Supplementary chapter: Number Systems
7.1 What is a number base?
7.2 Binary numbers
7.3 Hexadecimal numbers
7.4 Conversions
7.5 Seven-bit ASCII, 8-bit ASCII, Unicode: How many digits do we need?
8. Supplementary chapter: Introduction to security-conscious coding
8.1 What you already know
8.2 What do malicious actors do?
8.3 Know your data
8.4 Validating type with exception handling
8.5 Restricting input size with files
8.6 Validating input with string functions and regular expressions
9. Supplementary chapter: Recursion
9.1 Recursive problems
9.2 The call stack
9.3 Designing recursive solutions
References
Index