Python Programming in Context

Book description

A user-friendly, object-oriented language, Python is quickly becoming the favorite introductory programming language among students and instructors. Many find Python to be a more lucid language than Java but with much of the functionality and therefore the ideal first language for those entering the world of Computer Science. Python Programming in Context is a clear, accessible introduction to the fundamental programming and problem solving concepts necessary for students at this level. The authors carefully build upon the many important computer science concepts and problem solving techniques throughout the text and offer relevant, real-world examples and exercises to reinforce key material. Programming skills throughout the text are linked to applied areas such as Image Processing, Cryptography, Astronomy, Music, the Internet, and Bioinformatics, giving students a well rounded look of its capabilities.

Table of contents

  1. Book Cover
  2. Title
  3. Copyright
  4. Preface (1/2)
  5. Preface (2/2)
  6. Contents (1/3)
  7. Contents (2/3)
  8. Contents (3/3)
  9. Chapter 1 Introduction
    1. 1.1 Objectives
    2. 1.2 What Is Computer Science?
    3. 1.3 Why Study Computer Science?
      1. 1.3.1 Everyday Applications of Computer Science
      2. 1.3.2 Why Computer Science Is Important
    4. 1.4 Problem-Solving Strategies
    5. 1.5 Python Overview
      1. 1.5.1 Primitive Elements (1/2)
      2. 1.5.1 Primitive Elements (2/2)
        1. Integer Numbers
        2. Floating-Point Numbers
        3. Complex Numbers
        4. Summary of Numeric Types
      3. 1.5.2 Naming Objects (1/2)
      4. 1.5.2 Naming Objects (2/2)
      5. 1.5.3 Abstraction (1/2)
      6. 1.5.3 Abstraction (2/2)
        1. The cTurtle Module
        2. Writing Your Own Function
      7. 1.5.4 Repetition (1/2)
      8. 1.5.4 Repetition (2/2)
        1. Drawing a Spiral
        2. Drawing a Circle
    6. Exercises
    7. 1.6 Summary
    8. Key Terms
    9. Python Keywords
    10. Bibliography
    11. Programming Exercises
  10. Chapter 2 πthon
    1. 2.1 Objectives
    2. 2.2 What Is Pi?
    3. 2.3 More About the math Module
    4. 2.4 The Archimedes Approach
      1. 2.4.1 The Python Implementation
      2. 2.4.2 Developing a Function to Compute Pi
    5. 2.5 Accumulator Approximations
      1. 2.5.1 The Accumulator Pattern
      2. 2.5.2 Summation of Terms: The Leibniz Formula
      3. 2.5.3 Product of Terms: The Wallis Formula
    6. 2.6 A Monte Carlo Simulation
      1. 2.6.1 Boolean Expressions
      2. 2.6.2 Compound Boolean Expressions and Logical Operators
      3. 2.6.3 Selection Statements
      4. 2.6.4 Completing the Implementation
      5. 2.6.5 Adding Graphics
    7. Exercises
    8. 2.7 Summary
    9. Key Terms
    10. Python Keywords
    11. Bibliography
    12. Programming Exercises
  11. Chapter 3 Codes and Other Secrets
    1. 3.1 Objectives
    2. 3.2 Introduction
      1. 3.2.1 Concatenation
      2. 3.2.2 Repetition
      3. 3.2.3 Indexing
      4. 3.2.4 Slicing
      5. 3.2.5 String Methods
      6. 3.2.6 Character Functions
    3. 3.3 Encoding and Decoding Messages
    4. 3.4 Transposition Cipher
      1. 3.4.1 Encrypting Using Transposition
      2. 3.4.2 Decrypting a Transposed Message
      3. 3.4.3 Asking for Input
    5. 3.5 Substitution Cipher
    6. 3.6 Creating a Key (1/2)
    7. 3.6 Creating a Key (2/2)
    8. 3.7 The Vignère Cipher
    9. Exercises
    10. 3.8 Summary
    11. Key Terms
    12. Python Keywords
    13. Bibliography
    14. Programming Exercises
  12. Chapter 4 A Nest of Snakes: Introducing the Python Collections
    1. 4.1 Objectives
    2. 4.2 What Is Data?
    3. 4.3 Storing Data for Processing
      1. 4.3.1 Strings Revisited
      2. 4.3.2 Lists (1/2)
      3. 4.3.2 Lists (2/2)
    4. 4.4 Simple Dispersion
    5. 4.5 Central Tendency
      1. 4.5.1 Mean
      2. 4.5.2 Median
      3. 4.5.3 Mode (1/2)
      4. 4.5.3 Mode (2/2)
        1. Python Dictionaries
        2. Computing the Mode
    6. 4.6 Frequency Distribution
      1. 4.6.1 Using a Dictionary to Compute a Frequency Table
      2. 4.6.2 Computing a Frequency Table Without a Dictionary
      3. 4.6.3 Visualizing a Frequency Distribution
    7. 4.7 Dispersion: Standard Deviation
    8. Exercises
    9. 4.8 Summary
    10. Key Terms
    11. Python Keywords
    12. Bibliography
    13. Programming Exercises
  13. Chapter 5 Earthquakes, Floods, and Other Natural Disasters
    1. 5.1 Objectives
    2. 5.2 Using Files for Large Data Sets
      1. 5.2.1 Iterating over Lines in a File
      2. 5.2.2 Writing a File
      3. 5.2.3 String Formatting
      4. 5.2.4 Alternative File-Reading Methods
      5. 5.2.5 Statistics with Real Data
        1. Earthquakes
        2. Earthquake Statistics
    3. 5.3 Reading Data from the Internet
      1. 5.3.1 Using a while Loop to Process Data
      2. 5.3.2 Stock Market Data (1/2)
      3. 5.3.2 Stock Market Data (2/2)
        1. Accessing Stock Data
        2. Correlating Stock Data
    4. Exercises
    5. 5.4 Summary
    6. Key Terms
    7. Python Keywords
    8. Bibliography
    9. Programming Exercise
  14. Chapter 6 Pycture Perfect Programs
    1. 6.1 Objectives
    2. 6.2 What Is Digital Image Processing?
      1. 6.2.1 The RGB Color Model
      2. 6.2.2 The cImage Module
        1. The Pixel Object
        2. The ImageWin Object
        3. The FileImage Object
        4. The EmptyImage Object
    3. 6.3 Basic Image Processing
      1. 6.3.1 Negative Images
      2. 6.3.2 Grayscale
      3. 6.3.3 A General Solution: The Pixel Mapper
    4. 6.4 Parameters, Parameter Passing, and Scope
      1. 6.4.1 Call by Assignment Parameter Passing
      2. 6.4.2 Namespaces
      3. 6.4.3 Calling Functions and Finding Names
      4. 6.4.4 Modules and Namespaces
    5. 6.5 Advanced Image Processing
      1. 6.5.1 Resizing
      2. 6.5.2 Stretching: A Different Perspective
      3. 6.5.3 Flipping an Image
      4. 6.5.4 Edge Detection (1/2)
      5. 6.5.4 Edge Detection (2/2)
    6. Exercises
    7. 6.6 Summary
    8. Key Terms
    9. Python Keywords
    10. Bibliography
    11. Programming Exercises
  15. Chapter 7 Data Mining: Cluster Analysis
    1. 7.1 Objectives
    2. 7.2 What Is Data Mining?
    3. 7.3 Cluster Analysis: A Simple Example
    4. 7.4 Implementing Cluster Analysis on Simple Data
      1. 7.4.1 Distance Between Two Points
      2. 7.4.2 Clusters and Centroids
      3. 7.4.3 The K-Means Cluster Analysis Algorithm
      4. 7.4.4 Implementation of K-Means (1/2)
      5. 7.4.4 Implementation of K-Means (2/2)
        1. Indefinite Iteration
        2. The while loop
      6. 7.4.5 Implementation of K-Means Continued
    5. 7.5 Implementing Cluster Analysis: Earthquakes
      1. 7.5.1 File Processing
      2. 7.5.2 Visualization
    6. 7.6 Cluster Analysis Shortcomings and Solutions
    7. Exercises
    8. 7.7 Summary
    9. Key Terms
    10. Python Keywords
    11. Bibliography
    12. Programming Exercises
  16. Chapter 8 Cryptanalysis
    1. 8.1 Objectives
    2. 8.2 Introduction
    3. 8.3 Cracking the Rail Fence
      1. 8.3.1 Checking Our Work with a Dictionary
      2. 8.3.2 A Brute Force Solution
      3. 8.3.3 A Rail Fence Decryption Algorithm
    4. 8.4 Cracking the Substitution Cipher
      1. 8.4.1 Letter Frequency
      2. 8.4.2 Ciphertext Frequency Analysis
      3. 8.4.3 Letter Pair Analysis (1/2)
      4. 8.4.3 Letter Pair Analysis (2/2)
      5. 8.4.4 Word Frequency Analysis
      6. 8.4.5 Pattern Matching with Partial Words (1/2)
      7. 8.4.5 Pattern Matching with Partial Words (2/2)
      8. 8.4.6 Regular Expression Summary
    5. Exercises
    6. 8.5 Summary
    7. Key Terms
    8. Python Keywords
    9. Bibliography
    10. Programming Exercises
  17. Chapter 9 Fractals: The Geometry of Nature
    1. 9.1 Objectives
    2. 9.2 Introduction
    3. 9.3 Recursive Programs
      1. 9.3.1 Recursive Squares
      2. 9.3.2 Classic Recursive Functions
      3. 9.3.3 Drawing a Recursive Tree
      4. 9.3.4 The Sierpinski Triangle
      5. 9.3.5 Call Tree for a Sierpinski Triangle
    4. 9.4 Snowflakes, Lindenmayer, and Grammars
      1. 9.4.1 L-Systems
      2. 9.4.2 Automatically Expanding Production Rules
      3. 9.4.3 More Advanced L-Systems
    5. Exercises
    6. 9.5 Summary
    7. Key Terms
    8. Python Keywords
    9. Bibliography
    10. Programming Exercises
  18. Chapter 10 Astronomy
    1. 10.1 Objectives
    2. 10.2 Introduction
      1. 10.2.1 Programming
      2. 10.2.2 Object-Oriented Programming
      3. 10.2.3 Python Classes
    3. 10.3 Designing and Implementing a Planet Class
      1. 10.3.1 Constructor Method
      2. 10.3.2 Accessor Methods
      3. 10.3.3 Mutator Methods
      4. 10.3.4 Special Methods
      5. 10.3.5 Methods and self
      6. 10.3.6 Details of Method Storage and Lookup
    4. 10.4 Designing and Implementing a Sun Class
    5. 10.5 Designing and Implementing a Solar System
    6. 10.6 Animating the Solar System
      1. 10.6.1 Using Turtles
      2. 10.6.2 Planetary Orbits
        1. Distance Between Objects
        2. Velocity
        3. Acceleration
        4. Calculating Distance from Velocity and Velocity from Acceleration
        5. Mass and Gravity
        6. Interaction of the Planets
      3. 10.6.3 Implementation
    7. Exercises
    8. 10.7 Summary
    9. Key Terms
    10. Python Keywords
    11. Bibliography
    12. Programming Exercises
  19. Chapter 11 Bears, Fish, and Plants, Oh My!
    1. 11.1 Objectives
    2. 11.2 Bears and Fish
    3. 11.3 What Is a Simulation?
    4. 11.4 Rules of the Game
    5. 11.5 Design
    6. 11.6 Implementation
      1. 11.6.1 The World Class
      2. 11.6.2 The Fish Class (1/2)
      3. 11.6.2 The Fish Class (2/2)
      4. 11.6.3 The Bear Class
      5. 11.6.4 Main Simulation
    7. 11.7 Growing Plants
    8. Exercises
    9. 11.8 A Note on Inheritance
    10. 11.9 Summary
    11. Key Terms
    12. Python Keywords
    13. Bibliography
    14. Programming Exercises
  20. Chapter 12 Your Father Was a Rectangle
    1. 12.1 Objectives
    2. 12.2 Introduction
    3. 12.3 First Design (1/2)
    4. 12.3 First Design (2/2)
    5. 12.4 Basic Implementation
      1. 12.4.1 Canvas
      2. 12.4.2 GeometricObject
      3. 12.4.3 Point
      4. 12.4.4 Line
      5. 12.4.5 Testing Our Implementation
    6. 12.5 Understanding Inheritance
    7. 12.6 Limitations
    8. 12.7 An Improved Implementation
    9. 12.8 Implementing Polygons
    10. Exercises
    11. 12.9 Summary
    12. Key Terms
    13. Python Keywords
    14. Programming Exercises
  21. Chapter 13 Video Games
    1. 13.1 Objectives
    2. 13.2 Introduction
      1. 13.2.1 Event-Driven Programming
      2. 13.2.2 Simulating an Event Loop
      3. 13.2.3 A Multithreaded Event Loop
    3. 13.3 Event-Driven Programming with cTurtle
      1. 13.3.1 A Simple Etch-a-Sketch
      2. 13.3.2 Placing Turtles
      3. 13.3.3 Bouncing Turtles
    4. 13.4 Creating Your Own Video Game
      1. 13.4.1 The LaserCannon Class
      2. 13.4.2 The BoundedTurtle Class
      3. 13.4.3 The Alien Class
      4. 13.4.4 The Bomb Class
      5. 13.4.5 Putting All the Pieces Together
    5. Exercises
    6. 13.5 Summary
    7. Key Terms
    8. Bibliography
    9. Python Keywords
    10. Programming Exercises
  22. Appendix A: Installing the Required Software
  23. Appendix B: Python Quick Reference (1/4)
  24. Appendix B: Python Quick Reference (2/4)
  25. Appendix B: Python Quick Reference (3/4)
  26. Appendix B: Python Quick Reference (4/4)
  27. Appendix C: cTurtle Reference (1/2)
  28. Appendix C: cTurtle Reference (2/2)
  29. Index (1/2)
  30. Index (2/2)

Product information

  • Title: Python Programming in Context
  • Author(s): Bradley N. Miller, David L. Ranum
  • Release date: October 2010
  • Publisher(s): Jones & Bartlett Learning
  • ISBN: 9781449613099