Learn to Code by Solving Problems: A Python Programming Primer
β Scribed by Daniel Zingaro
- Publisher
- No Starch Press
- Year
- 2021
- Tongue
- English
- Leaves
- 339
- Edition
- 1
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Learn to Code by Solving Problems isΒ a practical introduction to programming using Python. It uses coding-competition challenges to teach you the mechanics of coding and how to think like a savvy programmer.
Computers are capable of solving almost any problem when given the right instructions. Thatβs where programming comes in. This beginnerβs book will have you writing Python programs right away. Youβll solve interesting problems drawn from real coding competitions and build your programming skills as you go.
Every chapter presents problems from coding challenge websites, where online judges test your solutions and provide targeted feedback. As you practice using core Python features, functions, and techniques, youβll develop a clear understanding of data structures, algorithms, and other programming basics. Bonus exercises invite you to explore new concepts on your own, and multiple-choice questions encourage you to think about how each piece of code works.
Youβll learn how to:
β’ Run Python code, work with strings, and use variables
β’ Write programs that make decisions
β’ Make code more efficient with while and for loops
β’ Use Python sets, lists, and dictionaries to organize, sort, and search data
β’ Design programs using functions and top-down design
β’ Create complete-search algorithms and use Big O notation to design more efficient code
By the end of the book, youβll not only be proficient in Python, but youβll also understand how to think through problems and tackle them with code. Programming languages come and go, but this book gives you the lasting foundation you need to start thinking like a programmer.
β¦ Table of Contents
About the Author
Brief Contents
Contents in Detail
Acknowledgments
Introduction
Online Resources
Who This Book Is For
Why Learn Python?
Installing Python
Windows
macOS
Linux
How to Read This Book
Using Programming Judges
Making Your Programming Judge Accounts
The DMOG Judge
The Timus Judge
The USACO Judge
About This Book
Chapter 1: Getting Started
What We'll Be Doing
The Python Shell
Windows
macOS
Linux
Problem #1: Word Count
The Challenge
Input
Output
Strings
Representing Strings
String Operators
String Methods
Integer and Floating-Point Numbers
Variables
Assignment Statement
Changing Variable Values
Counting the Words Using a Variable
Reading Input
Writing Output
Solving the Problem: A Complete Python Program
Launching a Text Editor
The Program
Running the Program
Submitting to the Judge
Problem #2: Cone Volume
The Challenge
Input
Output
More Math in Python
Accessing Pi
Exponents
Converting Between Strings and Integers
Solving the Problem
Summary
Chapter Exercises
Notes
Chapter 2: Making Decisions
Problem #3: Winning Team
The Challenge
Input
Output
Conditional Execution
The Boolean Type
Relational Operators
The if Statement
if by Itself
if with elif
if with else
Solving the Problem
Problem #4: Telemarketers
The Challenge
Input
Output
Boolean Operators
or Operator
and Operator
not Operator
Solving the Problem
Comments
Input and Output Redirection
Summary
Chapter Exercises
Notes
Chapter 3: Repeating Code: Definite Loops
Problem #5: Three Cups
The Challenge
Input
Output
Why Loops?
for Loops
Nesting
Solving the Problem
Problem #6: Occupied Spaces
The Challenge
Input
Output
A New Kind of Loop
Indexing
Range for loops
Range for Loops Through Indices
Solving the Problem
Problem #7: Data Plan
The Challenge
Input
Output
Looping to Read Input
Solving the Problem
Summary
Chapter Exercises
Notes
Chapter 4: Repeating Code: Indefinite Loops
Problem #8: Slot Machines
The Challenge
Input
Output
Exploring a Test Case
A Limitation of for Loops
while loops
Using while loops
Nesting Loops in Loops
Adding Boolean Operators
Solving the Problem
The Mod Operator
F-Strings
Problem #9: Song Playlist
The Challenge
Input
Output
String Slicing
Solving the Problem
Problem #10: Secret Sentence
The Challenge
Input
Output
Another Limitation of for loops
while Loops Through Indices
Solving the Problem
break and continue
break
continue
Summary
Chapter Exercises
Notes
Chapter 5: Organizing Values Using Lists
Problem #11: Village Neighborhood
The Challenge
Input
Output
Why Lists?
Lists
List Mutability
Learning About Methods
List Methods
Adding to a List
Sorting a List
Removing Values from a List
Solving the Problem
Avoiding Code Duplication: Two More Solutions
Using a Huge Size
Building a List of Sizes
Problem #12: School Trip
The Challenge
Input
Output
A Catch
Splitting Strings and Joining Lists
Splitting a String into a List
Joining a List into a String
Changing List Values
Solving Most of the Problem
Exploring a Test Case
The Code
How to Handle the Catch
Exploring a Test Case
More List Operations
Finding the Index of the Maximum
Solving the Problem
Problem #13: Baker Bonus
The Challenge
Input
Output
Representing a Table
Exploring a Test Case
Nested Lists
Solving the Problem
Summary
Chapter Exercises
Notes
Chapter 6: Designing Programs with Functions
Problem #14: Card Game
The Challenge
Input
Output
Exploring a Test Case
Defining and Calling Functions
Functions Without Arguments
Functions with Arguments
Keyword Arguments
Local Variables
Mutable Parameters
Return Values
Function Documentation
Solving the Problem
Problem #15: Action Figures
The Challenge
Input
Output
Representing the Boxes
Top-Down Design
Doing Top-Down Design
The Top Level
Task 1: Read Input
Task 2: Check Whether All Boxes Are OK
Task 3: Obtain a New List of Boxes with Only Left and Right Heights
Task 4: Sort Boxes
Task 5: Determine Whether Boxes Are Organized
Putting It All Together
Summary
Chapter Exercises
Notes
Chapter 7: Reading and Writing Files
Problem #16: Essay Formatting
The Challenge
Input
Output
Working with Files
Opening a File
Reading from a File
Writing to a File
Solving the Problem
Exploring a Test Case
The Code
Problem #17: Farming Seeding
The Challenge
Input
Output
Exploring a Test Case
Top-Down Design
The Top Level
Task 1: Read Input
Task 2: Identify Cows
Task 3: Eliminate Grass Types
Task 4: Choose Smallest-Numbered Grass Type
Task 5: Write Output
Summary
Chapter Exercises
Notes
Chapter 8: Organizing Values Using Sets and Dictionaries
Problem #18: Email Addresses
The Challenge
Input
Output
Using a List
Cleaning an Email Address
The Main Program
Efficiency of Searching a List
Sets
Set Methods
Effiency of Searching a Set
Solving the Problem
Problem #19: Common Words
The Challenge
Input
Output
Dictionaries
Indexing Dictionaries
Looping Through Dictionaries
Inverting a Dictionary
Solving the Problem
The Code
Adding the Suffix
Finding the kth Most Common Words
The Main Program
Problem #20: Cities and States
The Challenge
Input
Output
Exploring a Test Case
Solving the Problem
Summary
Chapter Exercises
Notes
Chapter 9: Designing Algorithms with Complete Search
Problem #21: Lifeguards
The Challenge
Input
Output
Exploring a Test Case
Solving the Problem
Firing One Lifeguard
The Main Program
Efficiency of Our Program
Problem #22: Ski Hills
The Challenge
Input
Output
Exploring a Test Case
Solving the Problem
Determining the Cost of One Range
The Main Program
Problem #23: Cow Baseball
The Challenge
Input
Output
Using Three Nested Loops
The Code
Efficiency of Our Program
Sorting First
The Code
Efficiency of Our Program
Python Modules
The bisect Module
Solving the Problem
Summary
Chapter Exercises
Notes
Chapter 10: Big O and Program Efficiency
The Problem with Timing
Big O
Constant Time
Linear Time
Quadratic Time
Cubic Time
Multiple Variables
Log Time
n log n Time
Handling Function Calls
Problem #24: Longest Scarf
The Challenge
Input
Output
Exploring a Test Case
Algorithm 1
Algorithm 2
Problem #25: Ribbon Painting
The Challenge
Input
Output
Exploring a Test Case
Solving the Problem
Summary
Chapter Exercises
Notes
Afterword
Problem Credits
Index
β¦ Subjects
Algorithms; Programming; Python; Search Algorithms; Algorithm Complexity; Competitive Programming; Elementary
π SIMILAR VOLUMES
<div> <p><span style="font-weight: bold; font-style: italic">Learn to Code by Solving Problems</span><strong> is a practical introduction to programming using Python. It uses coding-competition challenges to teach you the mechanics of coding and how to think like a savvy programmer.</strong> </p>
Learn to Code by Solving Problems is a practical introduction to programming using Python. It uses coding-competition challenges to teach you the mechanics of coding and how to think like a savvy programmer. Computers are capable of solving almost any problem when given the right instructions. Thatβ
<h2><span>The world of Python programming is booming! Get a slice of the action.</span></h2><p><span>Have you always wanted to be a part of the programming world, but things seem confusing and complicated so youβve never gone through with it? </span></p><p><span>Are you hoping to get a career in pro