Learn Programming with Python
Ana Bell
  • MEAP began October 2016
  • Publication in April 2017 (estimated)
  • ISBN 9781617293788
  • 400 pages (estimated)
  • printed in black & white

Computer programming is one of the most marketable skills you can add to your resume. Whether you want to become a professional software developer, create web sites, analyze scientific data, or just automate tedious business tasks, learning to program is the first step. Fortunately, learning to program doesn't have to be difficult. All you need is some help to get going. Filled with practical examples and step-by-step lessons using the easy-on-the-brain Python language, this book will get you started!

Learn Programming with Python is an introduction to the core skills and uses of computer programming. After a jargon-free guide to setting up your programming environment, you'll dive into the basics hands-on by writing your first programs! This easy-to-follow tutorial is full of exercises to practice and reinforce each new concept, so you'll have the confidence to move on to each new bite-sized lesson. As you progress, you'll learn programming topics and concepts common to all programming languages. By the end of the book, you'll have a practical grasp of how to write Python programs along with some solid programming best practices.

Table of Contents detailed table of contents

Unit 0 : Python and Your Programming Environment

Lesson 1 Why Should You Learn How to Program?

1.1 Why Programming Matters

1.1.1 Programming is not just for Professionals

1.1.2 Improve your Life

1.1.3 Challenge Yourself

1.2 Where you are now and where you will be

1.3 Our Plan for Learning how to Program

1.3.1 First Steps

1.3.2 Practice, practice, practice, practice

1.3.3 Thinking like a programmer

1.4 Summary

Lesson 2 Basic Principles of Learning a Programming Language

2.1 Programming as a Skill

2.2 A Parallel with Baking

2.2.1 Understand the Task “bake a loaf of bread”

2.2.2 The Recipe

2.2.3 Visualizing the Recipe with Flowcharts

2.2.4 Use an Existing Recipe or Make One Up?

2.3 Think, Code, Test, Debug, Repeat

2.3.1 Understanding the Task

2.3.2 Visualizing the Task

2.3.3 Writing Pseudocode

2.4 Writing Readable Code

2.4.1 Using Descriptive and Meaningful Names

2.4.2 Commenting Your Code

2.5 Summary

2.6 Answers to Quick Checks

Unit 1: Variables, Types, Expressions, and Statements

Lesson 3 Introducing Python: A Programming Language

3.1 Installing Python

3.1.1 What is Python?

3.1.2 Downloading Python Version 3.5

3.1.3 Anaconda Python Distribution

3.1.4 Integrated Development Environments

3.2 Setting up your Workspace

3.2.1 The IPython Console

3.2.2 The File Editor

3.3 Summary

3.4 Answers to Quick Checks

Lesson 4 Variables and Expressions: Giving Names and Values to Things

4.1 Giving Names to Things

4.1.1 Math versus Programming

4.1.2 What the Computer Can and Cannot Do

4.2 Introducing Variables

4.2.1 Objects are Things that can be Manipulated

4.2.2 Objects have Names

4.2.3 What Object Names are Allowed?

4.2.4 Creating a Variable

4.2.5 Updating a Variable

4.3 Summary

4.4 Answers to Quick Checks

4.5 Answers to Summary Questions

Lesson 5 Object Types and Statements of Code

5.1 Types of Things

5.2 Basic Type of Objects in Programming

5.2.1 Integers as Whole Numbers

5.2.2 Floating Point as Decimal Numbers

5.2.3 Booleans as True/False Data

5.2.4 Strings as Sequences of Characters

5.2.5 The Absence of a Value

5.3 Working with Basic Types of Data Values

5.3.1 Building Blocks of Expressions

5.3.2 Converting Between Different Types

5.3.3 How Arithmetic Impacts Object Types

5.4 Summary

5.5 Answers to Quick Checks

Lesson 6 Capstone Project: Your First Python Program: Convert Hours to Minutes

6.1 Think-Code-Test-Debug

6.2 Divide your Task

6.3 Implement the Conversion Formula

6.3.1 How many Hours?

6.3.2 How many Minutes?

6.4 Your First Python Program: One Solution

6.5 Your First Python Program: Another Solution

6.6 Summary

6.7 Answers to Quick Checks

6.8 Answers to Summary Exercises

Unit 2: Strings, Tuples, and Interacting with the User

Lesson 7 Introducing String Objects: Sequences of Characters

7.1 Strings as Sequences of Characters

7.2 Basic Operations on Strings

7.2.1 Creating a string Object

7.2.2 Understanding Indexing into a String

7.2.3 Understanding Slicing a string

7.3 Other Operations on string Objects

7.3.1 Getting the Number of Characters in a String with len()

7.3.2 Converting Between Letter Cases with upper() and lower()

7.4 Summary

7.5 Answers to Quick Checks

Lesson 8 Advanced String Operations

8.1.1 Find a Specific Substring in a String with find()

8.1.2 Find out if a Substring is in the String with “in”

8.1.3 Count how Many Times a Substring Occurs with count()

8.1.4 Replacing Substrings with replace()

8.2 Mathematical Operations

8.3 Summary

8.4 Answers to Quick Checks

8.5 Answers to Summary Exercises

Lesson 9 Simple Error Messages

9.1 Reading Basic Error Messages

9.1.1 Type Up Statements and Try Things Out

9.1.2 String Error Messages

9.2 Summary

Lesson 10 Tuple Objects: Sequences of any Kind of Object

10.1 Tuples as Sequences of Data

10.1.1 Understanding the Tuple Object Representation

10.2 Understanding Operations on Tuples

10.2.1 Getting the tuple Length with len()

10.2.2 Indexing into and Slicing a tuple with []

10.2.3 Mathematical Operations

10.2.4 Swapping Objects Inside tuples

10.3 Summary

10.4 Answers to Quick Checks

10.5 Answers to Summary Exercises

Lesson 11 Interacting with the User

11.1 Showing Output

11.1.1 Printing Expressions

11.1.2 Printing Multiple Objects

11.2 Getting User Input

11.2.1 Prompting the User

11.2.2 Reading the Input

11.2.3 Storing the Input in a Variable

11.2.4 Converting the User Input to a Different Type

11.2.5 Asking for More Inputs

11.3 Summary

11.4 Answers to Quick Checks

11.5 Answers to Summary Exercises

Lesson 12 Capstone Project: Name Mashup

12.1 Understanding the Problem Statement

12.1.1 Drawing out a Sketch of the Problem

12.1.2 Coming up with a few Examples

12.1.3 Abstracting the Problem into Pseudocode

12.2 Splitting up First and Last Names

12.2.1 Finding the Space between the First and Last Name

12.2.2 Using Variables to Save Calculated Values

12.2.3 Testing what you have so Far

12.3 Storing the Halves of all Names

12.3.1 Finding the Midpoint of Names

12.4 Combining the Halves

12.5 Summary

Unit 3: Making Decisions in Your Programs

Lesson 13 Introducing Decisions in Programs

13.1 Making Decisions With Conditionals

13.1.1 Yes/No Questions and True/False Statements

13.1.2 Adding a Condition to a Statement

13.2 The Code to Make the Decision

13.2.1 Coding up a Decision — an Example

13.2.2 Coding up a Decision — a General Way

13.3 Structuring Your Programs

13.3.1 Making Many Decisions

13.3.2 Making Decisions Based on Other Decision's Outcomes

13.3.3 A More Complicated Example with Nested Conditionals

13.4 Summary

13.5 Answers to Quick Checks

13.6 Answers to Summary Questions

Lesson 14 Making More Complicated Decisions

14.1 Combining Multiple Conditions

14.1.1 Conditionals are Made up of True/False Expressions

14.1.2 Operator Precedence Rules

14.2 Choosing which Lines to Execute

14.2.1 Do this or that

14.2.2 Putting it All Together

14.2.3 Thinking in Terms of Code Blocks

14.3 Summary

14.4 Answers to Quick Checks

14.5 Answers to Summary Exercises

Lesson 15 Capstone Project: Choose Your Own Adventure

15.1 Outlining the Game Rules

15.2 Creating Different Paths

15.3 More Choices? Yes, Please!

15.4 Summary

Unit 4: Repeating Tasks

Lesson 16 Repeating Tasks with Loops

16.1 Repeating a Task

16.1.1 Adding Non-Linearity to Programs

16.1.2 Infinite Repetitions

16.2 Looping a Certain Number of Times

16.2.1 for Loops

16.3 Looping N Times

16.3.1 Loops over the Common Sequence 0 to N-1

16.3.2 Unrolling Loops

16.4 Summary

16.5 Answers to Quick Checks

16.6 Answers to Summary Exercises

Lesson 17 Customizing Loops

17.1 Customizing Loops

17.2 Looping Over Strings

17.3 Summary

17.4 Answers to Quick Checks

17.5 Answers to Summary Exercises

Lesson 18 Repeating Tasks while Conditions Hold

18.1 Looping While a Condition is True

18.1.1 Looping to Make a Guess

18.1.2 while Loops

18.1.3 Infinite Loop

18.2 for Loops vs while Loops

18.3 Manipulating Loops

18.3.1 Exiting Early out of a Loop

18.3.2 Going to the Beginning of a Loop

18.4 Checkpoint Exercises

18.5 Summary

18.6 Answers to Quick Checks

18.7 Answers to Summary Exercises

Lesson 19 Capstone Project: Scrabble, Art Edition

19.1 Understanding the Problem Statement

19.1.1 Change the Representation of all Valid Words

19.1.2 Making a Valid Word with the Given Tiles

19.2 Dividing Up your Code into Pieces

19.3 Summary

Unit 5: Organizing Your Code into Reusable Blocks

Lesson 20 Building Programs to Last

20.1 Breaking a Big Task into Smaller Tasks

20.1.1 Ordering an Item Online

20.1.2 Understanding the Main Points

20.2 Introducing Black Boxes of Code in Programming

20.2.1 Code Modules

20.2.2 Abstracting Code

20.2.3 Reusing Code

20.3 Subtasks Exist in their Own Environments

20.4 Summary

20.5 Answers to Quick Checks

20.6 Answers to Summary Exercises

Lesson 21 Achieving Modularity and Abstraction with Functions

21.1 Writing a Function

21.1.1 Function Basics: What the Function takes in

21.1.2 Function Basics: What the Function Does

21.1.3 Function Basics: What the Function Returns

21.2 Using Functions

21.2.1 Returning More than One Value

21.2.2 Functions without a return Statement

21.3 Documenting your Functions

21.4 Summary

21.5 Answers to Quick Checks

21.6 Answers to Summary Exercises

Lesson 22 Advanced Operations with Functions

22.1 Thinking about Functions with Two Different Hats

22.1.1 Writer Hat

22.1.2 User Hat

22.2 Function Scope

22.2.1 Simple Scoping Example

22.2.2 Scoping Rules

22.3 Nesting Functions

22.4 Passing Functions as Parameters

22.5 Returning a Function

22.6 Summary

22.7 Answers to Quick Checks

22.8 Answers to Summary Exercises

Lesson 23 Capstone Project: Analyze Your Friends

23.1 Reading a File

23.1.1 File Format

23.1.2 The Newline Character

23.1.3 Remove the Newline Character

23.1.4 Using Tuples to Store Information

23.1.5 What to Return

23.2 Sanitizing User Inputs

23.3 Testing and Debugging what you have so far

23.3.1 File Objects

23.3.2 Writing a Text File with Names and Phone Numbers

23.3.3 Opening Files for Reading

23.4 Reusing Functions

23.5 Analyze the Information

23.5.1 The Specification

23.5.2 Helper Functions

23.6 Summary

Unit 6: Working with Mutable Data Types

Lesson 24 Introducing Collections of data

Lesson 25 Lists

Lesson 26 Advanced Operations with Lists

Lesson 27 Dictionaries as maps between objects

Lesson 28 Aliasing and copying a mutable object

Lesson 29 Capstone Project: Document Similarity

Unit 7

Lesson 30 Objects and Classes

Lesson 31 Working with Classes

Lesson 32 Object Oriented Programming

Lesson 33 Capstone Project: The solar system

Unit 8

Lesson 34 Debugging

Lesson 35 Useful Libraries

Lesson 36 File Input and Output

Lesson 37 What is a GUI

Lesson 38 Capstone Project: Traffic Simulator

Appendixes

Appendix A: Python Cheat Sheet

Appendix B: Interesting Python Packages

What's inside

  • Learn programming fundamentals for any language
  • Programming language basics like functions, classes, and file input/output
  • Writing data-centric and mathematical programs
  • Creating programs with graphical user interfaces
  • Programming best practices

About the reader

No programming experience needed.

About the author

Ana Bell is a lecturer at MIT in the Electrical Engineering and Computer Science department, where she co-lectures the Introduction to Computer Science and Programming Using Python course aimed at students with no programming experience.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $34.99 pBook + eBook
MEAP eBook $27.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks