TAILIEUCHUNG - Think Python: How to Think Like a Computer Scientist

Think Python is an introduction to Python programming for beginners. It starts with basic concepts of programming, and is carefully designed to define all terms when they are first used and to develop each new concept in a logical progression. Larger pieces, like recursion and object-oriented programming are divided into a sequence of smaller steps and introduced over the course of several chapters. Some examples and exercises are based on Swampy, a Python package written by the author to demonstrate aspects of software design, and to give readers a chance to experiment with simple graphics and animation | How to think like a computer scientist Allen B. Downey November 2012 2 How to think like a computer scientist C Version Copyright C 2012 Allen B. Downey Permission is granted to copy distribute and or modify this document under the terms of the Creative Commons Attribution-NonCommercial Unported License which is available at http creativecommons . org licenses by-nc . The original form of this book is LATEX source code. Compiling this code has the effect of generating a device-independent representation of a textbook which can be converted to other formats and printed. This book was typeset by the author using latex dvips and ps2pdf among other free open-source programs. The LaTeX source for this book is available from http greenteapress. com thinkcpp and from the SVN repository http p thinkcpp. Contents 1 The way of the program 1 What is a programming language . 1 What is a program . 3 What is debugging . 4 Compile-time errors. 4 Run-time errors. 4 Logic errors and semantics . 4 Experimental debugging. 5 Formal and natural languages. 5 The first program. 7 Glossary. 8 2 Variables and types 11 More output. 11 Values. 12 Variables . 13 Assignment . 13 Outputting variables . 14 Keywords . 15 Operators . 16 Order of operations . 17 Operators for characters. 17 Composition . 18 Glossary . 18 3 Function 21 Floating-point . 21 Converting from double to int. 22 Math functions . 23 Composition . 24 Adding new functions . 24 Definitions and uses . 26 Programs with multiple functions . 27 Parameters and arguments . 28