Computer programming is a skill that can bring great enjoyment from the creativity involved in designing and implementing a solution to a problem. This classroom-tested and easy-to-follow textbook teaches the reader how to program using Python, an accessible language which can be learned incrementally. Through an extensive use of examples and practical exercises, students will learn to recognize and apply abstract patterns in programming, as well as how to inspect the state of a program using a debugger tool. Features: contains numerous examples and solved practice exercises designed for an interactive classroom environment; highlights several patterns which commonly appear in programs, and presents exercises that reinforce recognition and application of these patterns; introduces the use of a debugger, and includes supporting material that reveals how programs work; presents the Tkinter framework for building graphical user interface applications and event-driven programs; provides helpful additional resources for instructors at the associated website: http: //cs.luther.edu/ leekent/CS1. This hands-on textbook for active learning in the classroom will enable undergraduates in computer science to develop the necessary skills to begin developing their own programs. It employs Python as the introductory language due to the wealth of support available for programmers
Author(s): Kent D. Lee
Series: Undergraduate Topics in Computer Science
Edition: 1
Publisher: Springer
Year: 2010
Cover
Undergraduate Topics in Computer Science
Python
Programming
Fundamentals
ISBN 9781849965361
Preface
Acknowledgments
Credits
Suggestions
Contents
1 Introduction
The Python Programming Language
Installing Python and Wing IDE 101
Configuring Wing
Writing Your First Program
What is a Computer?
Binary Number Representation
What is a Programming Language?
Hexadecimal and Octal Representation
Writing Your Second Program
Syntax Errors
Types of Values
The Reference Type and Assignment Statements
Integers and Real Numbers
Strings
Integer to String Conversion and Back Again
Getting Input
Formatting Output
When Things Go Wrong
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 1.1
Solution to Practice Problem 1.2
Solution to Practice Problem 1.3
Solution to Practice Problem 1.4
Solution to Practice Problem 1.5
Solution to Practice Problem 1.6
Solution to Practice Problem 1.7
Solution to Practice Problem 1.8
Solution to Practice Problem 1.9
Solution to Practice Problem 1.10
Solution to Practice Problem 1.11
Solution to Practice Problem 1.12
Solution to Practice Problem 1.13
Solution to Practice Problem 1.14
Solution to Practice Problem 1.15
2 Decision Making
Finding the Max of Three Integers
The Guess and Check Pattern
Choosing from a List of Alternatives
The Boolean Type
Short Circuit Logic
Comparing Floats for Equality
Exception Handling
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 2.1
Solution to Practice Problem 2.2
Solution to Practice Problem 2.3
Solution to Practice Problem 2.4
Solution to Practice Problem 2.5
Solution to Practice Problem 2.6
Solution to Practice Problem 2.7
Solution to Practice Problem 2.8
3 Repetitive Tasks
Operators
Iterating Over a Sequence
Lists
The Guess and Check Pattern for Lists
Mutability of Lists
The Accumulator Pattern
Reading from and Writing to a File
Reading Records from a File
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 3.1
Solution to Practice Problem 3.2
Solution to Practice Problem 3.3
Solution to Practice Problem 3.4
Solution to Practice Problem 3.5
Solution to Practice Problem 3.6
Solution to Practice Problem 3.7
Solution to Practice Problem 3.8
Solution to Practice Problem 3.9
Solution to Practice Problem 3.10
Solution to Practice Problem 3.11
Solution to Practice Problem 3.12
Solution to Practice Problem 3.13
Solution to Practice Problem 3.14
4 Using Objects
Constructors
Accessor Methods
Mutator Methods
Immutable Classes
Object-Oriented Programming
Working with XML Files
Extracting Elements from an XML File
Dictionaries
Getting at the Data in an XML File
Working with Time
Parallel Lists
Visualizing a Workout
Draw the Axes
Plotting the Data
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 4.1
Solution to Practice Problem 4.2
Solution to Practice Problem 4.3
Solution to Practice Problem 4.4
Solution to Practice Problem 4.5
Solution to Practice Problem 4.6
Solution to Practice Problem 4.7
Solution to Practice Problem 4.8
Solution to Practice Problem 4.9
5 Defining Functions
Why Write Functions?
Passing Arguments and Returning a Value
Scope of Variables
The Run-time Stack
Mutable Data and Functions
Predicate Functions
Top-Down Design
Bottom-Up Design
Recursive Functions
The Main Function
Keyword Arguments
Default Values
Functions with Variable Number of Parameters
Dictionary Parameter Passing
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 5.1
Solution to Practice Problem 5.2
Solution to Practice Problem 5.3
Solution to Practice Problem 5.4
Solution to Practice Problem 5.5
Solution to Practice Problem 5.6
Solution to Practice Problem 5.7
Solution to Practice Problem 5.8
Solution to Practice Problem 5.9
Solution to Practice Problem 5.10
Solution to Practice Problem 5.11
Solution to Practice Problem 5.12
Solution to Practice Problem 5.13
Solution to Practice Problem 5.14
Solution to Practice Problem 5.15
6 Event-Driven Programming
The Root Window
Menus
Frames
The Text Widget
The Button Widget
Creating a Reminder!
Finishing up the Reminder! Application
Label and Entry Widgets
Layout Management
Message Boxes
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 6.1
Solution to Practice Problem 6.2
Solution to Practice Problem 6.3
Solution to Practice Problem 6.4
Solution to Practice Problem 6.5
Solution to Practice Problem 6.6
Solution to Practice Problem 6.7
7 Defining Classes
Creating an Object
Inheritance
A Bouncing Ball Example
Polymorphism
Getting Hooked on Python
Review Questions
Exercises
Solutions to Practice Problems
Solution to Practice Problem 7.1
Solution to Practice Problem 7.2
Solution to Practice Problem 7.3
Solution to Practice Problem 7.4
Solution to Practice Problem 7.5
Appendix A Integer Operators
Appendix B Float Operators
Appendix C String Operators and Methods
Appendix D List Operators and Methods
Appendix E Dictionary Operators and Methods
Appendix F Turtle Methods
Appendix G TurtleScreen Methods
Appendix H The Reminder! Program
Appendix I The Bouncing Ball Program
Glossary
References
Index