logo资料库

Introduction to Computation and Programming Using Python.pdf

第1页 / 共315页
第2页 / 共315页
第3页 / 共315页
第4页 / 共315页
第5页 / 共315页
第6页 / 共315页
第7页 / 共315页
第8页 / 共315页
资料共315页,剩余部分请下载后查看
Contents
Preface
Acknowledgments
1 Getting Started
2 Introduction to Python
2.1 The Basic Elements of Python
2.2 Branching Programs
2.3 Strings and Input
2.4 Iteration
3 Some Simple Numerical Programs
3.1 Exhaustive Enumeration
3.2 For Loops
3.3 Approximate Solutions and Bisection Search
3.4 A Few Words About Using Floats
3.5 Newton-Raphson
4 Functions, Scoping, and Abstraction
4.1 Functions and Scoping
4.2 Specifications
4.3 Recursion
4.4 Global Variables
4.5 Modules
4.6 Files
5 Structured Types, Mutability, and Higher-Order Functions
5.1 Tuples
5.2 Lists and Mutability
5.3 Functions as Objects
5.4 Strings, Tuples, and Lists
5.5 Dictionaries
6 Testing and Debugging
6.1 Testing
6.2 Debugging
7 Exceptions and Assertions
7.1 Handling Exceptions
7.2 Exceptions as a Control Flow Mechanism
7.3 Assertions
8 Classes and Object-Oriented Programming
8.1 Abstract Data Types and Classes
8.2 Inheritance
8.3 Encapsulation and Information Hiding
8.4 Mortgages, an Extended Example
9 A Simplistic Introduction to Algorithmic Complexity
9.1 Thinking About Computational Complexity
9.2 Asymptotic Notation
9.3 Some Important Complexity Classes
10 Some Simple Algorithms and Data Structures
10.1 Search Algorithms
10.2 Sorting Algorithms
10.3 Hash Tables
11 Plotting and More About Classes
11.1 Plotting Using PyLab
11.2 Plotting Mortgages, an Extended Example
12 Stochastic Programs, Probability, and Statistics
12.1 Stochastic Programs
12.2 Inferential Statistics and Simulation
12.3 Distributions
12.4 How Often Does the Better Team Win?
12.5 Hashing and Collisions
13 Random Walks and More About Data Visualization
13.1 The Drunkard’s Walk
13.2 Biased Random Walks
13.3 Treacherous Fields
14 Monte Carlo Simulation
14.1 Pascal’s Problem
14.2 Pass or Don’t Pass?
14.3 Using Table Lookup to Improve Performance
14.4 Finding π
14.5 Some Closing Remarks About Simulation Models
15 Understanding Experimental Data
15.1 The Behavior of Springs
15.2 The Behavior of Projectiles
15.3 Fitting Exponentially Distributed Data
15.4 When Theory Is Missing
16 Lies, Damned Lies, and Statistics
16.1 Garbage In Garbage Out (GIGO)
16.2 Pictures Can Be Deceiving
16.3 Cum Hoc Ergo Propter Hoc
16.4 Statistical Measures Don’t Tell the Whole Story
16.5 Sampling Bias
16.6 Context Matters
16.7 Beware of Extrapolation
16.8 The Texas Sharpshooter Fallacy
16.9 Percentages Can Confuse
16.10 Just Beware
17 Knapsack and Graph Optimization Problems
17.1 Knapsack Problems
17.2 Graph Optimization Problems
18 Dynamic Programming
18.1 Fibonacci Sequences, Revisited
18.2 Dynamic Programming and the 0/1 Knapsack Problem
18.3 Dynamic Programming and Divide-and-Conquer
19 A Quick Look at Machine Learning
19.1 Feature Vectors
19.2 Distance Metrics
19.3 Clustering
19.4 Types Example and Cluster
19.5 K-means Clustering
19.6 A Contrived Example
19.7 A Less Contrived Example
19.8 Wrapping Up
Python 2.7 Quick Reference
Index
Uploaded by [StormRG]
Introduction to Computation and Programming Using Python
Introduction to Computation and Programming Using Python Revised and Expanded Edition John V. Guttag The MIT Press Cambridge, Massachusetts London, England
©  2013  Massachusetts Institute of Technology   All  rights  reserved.  No  part  of  this  book  may  be  reproduced  in  any  form  by  any   electronic  or  mechanical  means  (including  photocopying,  recording,  or  information   storage  and  retrieval)  without  permission  in  writing  from  the  publisher.    MIT  Press  books  may  be  purchased  at  special  quantity  discounts  for  business  or   sales  promotional  use.  For  information,  please  email   special_sales@mitpress.mit.edu  or  write  to  Special  Sales  Department,  The  MIT   Press,  55  Hayward  Street,  Cambridge,  MA  02142.     Printed  and  bound  in  the  United  States  of  America.   Library  of  Congress  Cataloging-­‐in-­‐Publication  Data    Guttag,  John.   Introduction  to  computation  and  programming  using  Python  /  John  V.  Guttag.  —   Revised  and  expanded  edition.     pages   cm   Includes  index.   ISBN  978-­‐0-­‐262-­‐52500-­‐8  (pbk.  :  alk.  paper)     1.    Python  (Computer  program  language)  2.    Computer  programming.  I.  Title.     QA76.73.P48G88   2013   005.13'3—dc23   10   9   8   7   6   5   4   3   2   1  
To my family: Olga David Andrea Michael Mark Addie
CONTENTS PREFACE ....................................................................................................... xiii   ACKNOWLEDGMENTS ..................................................................................... xv   1   GETTING STARTED .................................................................................... 1   INTRODUCTION TO PYTHON ...................................................................... 7   2   2.1   The Basic Elements of Python ............................................................... 8   2.1.1   Objects, Expressions, and Numerical Types .................................... 9   2.1.2   Variables and Assignment ............................................................ 11   2.1.3   IDLE ............................................................................................ 13   2.2   Branching Programs ........................................................................... 14   2.3   Strings and Input ............................................................................... 16   Input ............................................................................................ 18   2.3.1   2.4   Iteration .............................................................................................. 18   3   SOME SIMPLE NUMERICAL PROGRAMS .................................................. 21   3.1   Exhaustive Enumeration .................................................................... 21   3.2   For Loops ............................................................................................ 23   3.3   Approximate Solutions and Bisection Search ...................................... 25   3.4   A Few Words About Using Floats ........................................................ 29   3.5   Newton-Raphson ................................................................................ 32   4   FUNCTIONS, SCOPING, and ABSTRACTION ............................................. 34   4.1   Functions and Scoping ....................................................................... 35   4.1.1   Function Definitions ..................................................................... 35   4.1.2   Keyword Arguments and Default Values ....................................... 36   4.1.3   Scoping ........................................................................................ 37   4.2   Specifications ..................................................................................... 41   4.3   Recursion ........................................................................................... 44   4.3.1   Fibonacci Numbers ...................................................................... 45   4.3.2   Palindromes ................................................................................. 48   4.4   Global Variables ................................................................................. 50   4.5   Modules .............................................................................................. 51   4.6   Files ................................................................................................... 53  
分享到:
收藏