Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..8
-
Upload
zhichaowang -
Category
Documents
-
view
221 -
download
0
description
Transcript of Introduction to Computation and Programming Using Python%2C Revised - Guttag%2C John v..8
-
CONTENTS
PREFACE ....................................................................................................... xiii ACKNOWLEDGMENTS ..................................................................................... xv 1 GETTING STARTED .................................................................................... 1 2 INTRODUCTION TO PYTHON ...................................................................... 7
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
2.3.1 Input ............................................................................................ 18 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