Book description
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
- Cover Page
- Title Page
- Copyright Page
- Dedication
- About the Author
- About the Technical Reviewer
- BRIEF CONTENTS
- CONTENTS IN DETAIL
- ACKNOWLEDGMENTS
- INTRODUCTION
-
1 GETTING STARTED
- What We’ll Be Doing
- The Python Shell
- Problem #1: Word Count
- Strings
- Integer and Floating-Point Numbers
- Counting the Words Using a Variable
- Reading Input
- Writing Output
- Solving the Problem: A Complete Python Program
- Problem #2: Cone Volume
- More Math in Python
- Converting Between Strings and Integers
- Solving the Problem
- Summary
- Chapter Exercises
- Notes
- 2 MAKING DECISIONS
- 3 REPEATING CODE: DEFINITE LOOPS
-
4 REPEATING CODE: INDEFINITE LOOPS
- Problem #8: Slot Machines
- Exploring a Test Case
- A Limitation of for loops
- while loops
- Solving the Problem
- The Mod Operator
- F-Strings
- Problem #9: Song Playlist
- String Slicing
- Solving the Problem
- Problem #10: Secret Sentence
- Another Limitation of for loops
- while Loops Through Indices
- Solving the Problem
- break and continue
- Summary
- Chapter Exercises
- Notes
-
5 ORGANIZING VALUES USING LISTS
- Problem #11: Village Neighborhood
- Why Lists?
- Lists
- List Mutability
- Learning About Methods
- List Methods
- Solving the Problem
- Avoiding Code Duplication: Two More Solutions
- Problem #12: School Trip
- Splitting Strings and Joining Lists
- Changing List Values
- Solving Most of the Problem
- How to Handle the Catch
- Problem #13: Baker Bonus
- Representing a Table
- Solving the Problem
- Summary
- Chapter Exercises
- Notes
- 6 DESIGNING PROGRAMS WITH FUNCTIONS
- 7 READING AND WRITING FILES
-
8 ORGANIZING VALUES USING SETS AND DICTIONARIES
- Problem #18: Email Addresses
- Using a List
- Efficiency of Searching a List
- Sets
- Set Methods
- Efficiency of Searching a Set
- Solving the Problem
- Problem #19: Common Words
- Exploring a Test Case
- Dictionaries
- Indexing Dictionaries
- Looping Through Dictionaries
- Inverting a Dictionary
- Solving the Problem
- Problem #20: Cities and States
- Exploring a Test Case
- Solving the Problem
- Summary
- Chapter Exercises
- Notes
- 9 DESIGNING ALGORITHMS WITH COMPLETE SEARCH
- 10 BIG O AND PROGRAM EFFICIENCY
- AFTERWORD
- APPENDIX: PROBLEM CREDITS
- INDEX
Product information
- Title: Learn to Code by Solving Problems
- Author(s):
- Release date: June 2021
- Publisher(s): No Starch Press
- ISBN: 9781718501324
You might also like
book
Head First Design Patterns, 2nd Edition
What will you learn from this book? You know you don't want to reinvent the wheel, …
book
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization …
book
Learning Go, 2nd Edition
Go has rapidly become the preferred language for building web services. Plenty of tutorials are available …
book
40 Algorithms Every Programmer Should Know
Learn algorithms for solving classic computer science problems with this concise guide covering everything from fundamental …