Download Fundamentals of Python First Programs 1st Edition Kenneth A. Lambert ebook All Chapters PDF
Download Fundamentals of Python First Programs 1st Edition Kenneth A. Lambert ebook All Chapters PDF
com
https://ebookname.com/product/fundamentals-of-python-first-
programs-1st-edition-kenneth-a-lambert/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/programming-fundamentals-a-modular-
structured-approach-using-c-kenneth-leroy-busbee/
ebookname.com
https://ebookname.com/product/word-2010-for-dummies-dan-gookin/
ebookname.com
Molecular Genetics and the Human Personality 1st ed
Edition Jonathan Benjamin
https://ebookname.com/product/molecular-genetics-and-the-human-
personality-1st-ed-edition-jonathan-benjamin/
ebookname.com
https://ebookname.com/product/wireless-information-networks-second-
edition-kaveh-pahlavan/
ebookname.com
https://ebookname.com/product/hereditary-gynecologic-cancer-risk-
prevention-and-management-1st-edition-karen-h-lu/
ebookname.com
https://ebookname.com/product/oxford-handbook-of-urology-3rd-edition-
john-reynard/
ebookname.com
https://ebookname.com/product/design-basics-seventh-edition-with-
artexperience-online-printed-access-card-david-a-lauer/
ebookname.com
Hypertension A Medical Dictionary Bibliography and
Annotated Research Guide to Internet References Health
Publica Icon Health Publications
https://ebookname.com/product/hypertension-a-medical-dictionary-
bibliography-and-annotated-research-guide-to-internet-references-
health-publica-icon-health-publications/
ebookname.com
Fundamentals of
Python:
First Programs
Kenneth A. Lambert
Martin Osborne, Contributing Author
Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Fundamentals of Python: First Programs © 2012 Course Technology, Cengage Learning
Kenneth A. Lambert ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
Executive Editor: Marie Lee
any means graphic, electronic, or mechanical, including but not limited to
Acquisitions Editor: Brandi Shailer photocopying, recording, scanning, digitizing, taping, Web distribution,
Senior Product Manager: Alyssa Pratt information networks, or information storage and retrieval systems, except
Development Editor: Ann Shaffer as permitted under Section 107 or 108 of the 1976 United States Copyright
Act, without the prior written permission of the publisher.
Associate Product Manager: Stephanie
Lorenz
For product information and technology assistance, contact us at
Associate Marketing Manager: Shanna
Cengage Learning Customer & Sales Support, 1-800-354-9706
Shelton
For permission to use material from this text or product, submit all
Content Project Manager: Jennifer Feltri requests online at www.cengage.com/permissions
Art Director: Faith Brosnan Further permissions questions can be emailed to
permissionrequest@cengage.com
Image credit: © istockphoto/Pei Ling Hoo
Cover Designer: Wing-ip Ngan,
Ink design, Inc. Library of Congress Control Number: 2011920241
Compositor: GEX Publishing Services ISBN-13: 978-1-111-82270-5
ISBN-10: 1-111-82270-0
Course Technology
20 Channel Center
Boston, Massachusetts 02210
USA
Purchase any of our products at your local college store or at our preferred
online store www.cengagebrain.com.
Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or regis-
tered trademarks of their respective manufacturers and sellers.
Course Technology, a part of Cengage Learning, reserves the right to revise this
publication and make changes from time to time in its content without notice.
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents
[CHAPTER] 1 INTRODUCTION 1
1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information
Processing .................................................................................................................2
1.1.1 Algorithms ................................................................................................2
1.1.2 Information Processing............................................................................4
1.1 Exercises....................................................................................................................5
1.2 The Structure of a Modern Computer System .......................................................6
1.2.1 Computer Hardware ................................................................................6
1.2.2 Computer Software..................................................................................8
1.2 Exercises..................................................................................................................10
1.3 A Not-So-Brief History of Computing Systems...................................................10
1.3.1 Before Electronic Digital Computers ...................................................11
1.3.2 The First Electronic Digital Computers (1940–1950) .........................15
1.3.3 The First Programming Languages (1950–1965).................................16
1.3.4 Integrated Circuits, Interaction, and Timesharing (1965–1975) .........18
1.3.5 Personal Computing and Networks (1975–1990) ................................19
1.3.6 Consultation, Communication, and Ubiquitous Computing
(1990–Present)........................................................................................21
1.4 Getting Started with Python Programming..........................................................23
1.4.1 Running Code in the Interactive Shell .................................................23
1.4.2 Input, Processing, and Output...............................................................25
1.4.3 Editing, Saving, and Running a Script ..................................................28
1.4.4 Behind the Scenes: How Python Works ...............................................29
1.4 Exercises..................................................................................................................30
1.5 Detecting and Correcting Syntax Errors...............................................................31
1.5 Exercises..................................................................................................................32
Suggestions for Further Reading ...........................................................................32
Summary .................................................................................................................33
Review Questions ...................................................................................................35
Projects....................................................................................................................37
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
2.3 Strings, Assignment, and Comments.....................................................................47
2.3.1 Data Types..............................................................................................47
2.3.2 String Literals.........................................................................................48
2.3.3 Escape Sequences ...................................................................................50
2.3.4 String Concatenation .............................................................................50
2.3.5 Variables and the Assignment Statement ..............................................51
2.3.6 Program Comments and Docstrings.....................................................52
2.3 Exercises..................................................................................................................53
2.4 Numeric Data Types and Character Sets ..............................................................54
2.4.1 Integers ...................................................................................................54
2.4.2 Floating-Point Numbers........................................................................55
2.4.3 Character Sets ........................................................................................55
2.4 Exercises..................................................................................................................57
2.5 Expressions .............................................................................................................58
2.5.1 Arithmetic Expressions ..........................................................................58
2.5.2 Mixed-Mode Arithmetic and Type Conversions ..................................60
2.5 Exercises..................................................................................................................63
2.6 Using Functions and Modules ...............................................................................63
2.6.1 Calling Functions: Arguments and Return Values................................64
2.6.2 The math Module .................................................................................65
2.6.3 The Main Module..................................................................................66
2.6.4 Program Format and Structure .............................................................67
2.6.5 Running a Script from a Terminal Command Prompt ........................68
2.6 Exercises..................................................................................................................70
Summary .................................................................................................................70
Review Questions ...................................................................................................72
Projects....................................................................................................................73
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
3.4.3 One-Way Selection Statements.............................................................94
3.4.4 Multi-way if Statements ......................................................................95
3.4.5 Logical Operators and Compound Boolean Expressions.....................97
3.4.6 Short-Circuit Evaluation .......................................................................99
3.4.7 Testing Selection Statements ...............................................................100
3.4 Exercises................................................................................................................101
3.5 Conditional Iteration: The while Loop ............................................................102
3.5.1 The Structure and Behavior of a while Loop ..................................102
3.5.2 Count Control with a while Loop....................................................104
3.5.3 The while True Loop and the break Statement ..........................105
3.5.4 Random Numbers................................................................................107
3.5.5 Loop Logic, Errors, and Testing .........................................................109
3.5 Exercises................................................................................................................109
3.6 Case Study: Approximating Square Roots...........................................................110
3.6.1 Request .................................................................................................110
3.6.2 Analysis .................................................................................................110
3.6.3 Design...................................................................................................110
3.6.4 Implementation (Coding) ....................................................................112
3.6.5 Testing ..................................................................................................113
Summary ...............................................................................................................113
Review Questions .................................................................................................116
Projects..................................................................................................................118
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4.5 Exercises................................................................................................................148
4.6 Case Study: Text Analysis.....................................................................................148
4.6.1 Request .................................................................................................149
4.6.2 Analysis .................................................................................................149
4.6.3 Design...................................................................................................150
4.6.4 Implementation (Coding) ....................................................................151
4.6.5 Testing ..................................................................................................152
Summary ...............................................................................................................153
Review Questions .................................................................................................154
Projects..................................................................................................................156
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
5.5 Case Study: Nondirective Psychotherapy ...........................................................191
5.5.1 Request .................................................................................................191
5.5.2 Analysis .................................................................................................191
5.5.3 Design...................................................................................................192
5.5.4 Implementation (Coding) ....................................................................193
5.5.5 Testing ..................................................................................................195
Summary ...............................................................................................................195
Review Questions .................................................................................................196
Projects..................................................................................................................198
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6.6 Exercises................................................................................................................239
Summary ...............................................................................................................240
Review Questions .................................................................................................242
Projects..................................................................................................................244
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
8.1.4 The __init__ Method and Instance Variables................................299
8.1.5 The __str__ Method........................................................................300
8.1.6 Accessors and Mutators .......................................................................300
8.1.7 The Lifetime of Objects ......................................................................301
8.1.8 Rules of Thumb for Defining a Simple Class.....................................302
8.1 Exercises................................................................................................................303
8.2 Case Study: Playing the Game of Craps .............................................................303
8.2.1 Request .................................................................................................303
8.2.2 Analysis .................................................................................................303
8.2.3 Design...................................................................................................304
8.2.4 Implementation (Coding) ....................................................................306
8.3 Data-Modeling Examples.....................................................................................309
8.3.1 Rational Numbers ................................................................................309
8.3.2 Rational Number Arithmetic and Operator Overloading..................311
8.3.3 Comparison Methods...........................................................................312
8.3.4 Equality and the __eq__ Method ......................................................314
8.3.5 Savings Accounts and Class Variables .................................................315
8.3.6 Putting the Accounts into a Bank........................................................317
8.3.7 Using pickle for Permanent Storage of Objects.............................319
8.3.8 Input of Objects and the try-except Statement............................320
8.3.9 Playing Cards .......................................................................................321
8.3 Exercises................................................................................................................325
8.4 Case Study: An ATM............................................................................................325
8.4.1 Request .................................................................................................325
8.4.2 Analysis .................................................................................................325
8.4.3 Design...................................................................................................327
8.4.4 Implementation (Coding) ....................................................................329
8.5 Structuring Classes with Inheritance and Polymorphism...................................331
8.5.1 Inheritance Hierarchies and Modeling ...............................................332
8.5.2 Example: A Restricted Savings Account..............................................333
8.5.3 Example: The Dealer and a Player in the Game of Blackjack ...........335
8.5.4 Polymorphic Methods..........................................................................340
8.5.5 Abstract Classes ...................................................................................340
8.5.6 The Costs and Benefits of Object-Oriented Programming...............341
8.5 Exercises................................................................................................................343
Summary ...............................................................................................................343
Review Questions .................................................................................................345
Projects..................................................................................................................346
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
9.2.5 Entry Fields for the Input and Output of Text ...................................363
9.2.6 Using Pop-up Dialog Boxes ................................................................365
9.2 Exercises................................................................................................................366
9.3 Case Study: A GUI-Based ATM..........................................................................367
9.3.1 Request .................................................................................................367
9.3.2 Analysis .................................................................................................367
9.3.3 Design...................................................................................................368
9.3.4 Implementation (Coding) ....................................................................369
9.4 Other Useful GUI Resources ..............................................................................372
9.4.1 Colors ...................................................................................................373
9.4.2 Text Attributes......................................................................................373
9.4.3 Sizing and Justifying an Entry .............................................................374
9.4.4 Sizing the Main Window.....................................................................375
9.4.5 Grid Attributes .....................................................................................376
9.4.6 Using Nested Frames to Organize Components................................380
9.4.7 Multi-Line Text Widgets .....................................................................381
9.4.8 Scrolling List Boxes .............................................................................384
9.4.9 Mouse Events .......................................................................................387
9.4.10 Keyboard Events ..................................................................................388
9.4 Exercises................................................................................................................389
Summary ...............................................................................................................390
Review Questions .................................................................................................391
Projects..................................................................................................................392
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
[ONLINE CHAPTER] 11 SEARCHING, SORTING, AND COMPLEXITY ANALYSIS
PREFACE [ xiii ]
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Why Python?
Computer technology and applications have become increasingly more sophisti-
cated over the past two decades, and so has the computer science curriculum, espe-
cially at the introductory level. Today’s students learn a bit of programming and
problem–solving, and are then expected to move quickly into topics like software
development, complexity analysis, and data structures that, twenty years ago, were
relegated to advanced courses. In addition, the ascent of object-oriented program-
ming as the dominant paradigm of problem solving has led instructors and text-
book authors to bring powerful, industrial-strength programming languages such as
C++ and Java into the introductory curriculum. As a result, instead of experiencing
the rewards and excitement of solving problems with computers, beginning com-
puter science students often become overwhelmed by the combined tasks of mas-
tering advanced concepts as well as the syntax of a programming language.
This book uses the Python programming language as a way of making the
first year of computer science more manageable and attractive for students and
instructors alike. Python has the following pedagogical benefits:
Python has simple, conventional syntax. Python statements are very close to
Python. Python also includes all of the advanced features of a modern pro-
gramming language, such as support for data structures and object-oriented
software development, for use when they become necessary.
Python is highly interactive. Expressions and statements can be entered at
[ xiv ] PREFACE
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of The
Evacuation of England: The Twist in the Gulf
Stream
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.
Author: L. P. Gratacap
Language: English
THE EVACUATION OF
ENGLAND
THE
Evacuation of England
THE TWIST IN THE GULF STREAM
BY
L. P. GRATACAP
AUTHOR OF
“THE CERTAINTY OF A FUTURE LIFE IN MARS,”
“A WOMAN OF THE ICE AGE”
NEW YORK
B R E N TA N O ’ S
1908
Copyright, 1908, by Brentano’s
CONTENTS
CHAPTER PAGE
I. In Washington, April, 1909 5
X. Addendum 298
THE EVACUATION OF ENGLAND
CHAPTER I.
IN WASHINGTON, APRIL, 1909.
Dear Leacraft:
Aunt Sophia is very sick at Litchfield, Conn. Mother and Sally
have gone on. Can you put off your visit until May, say the 28th? You
will find it dull here without Sally and Mother. I shall go with them as
far as New York. We all intend, if Aunt Sophy concludes to remain in
this bright world a little longer, and the Dr. endorses her good
intentions, to visit Gettysburg on Memorial Day (Decoration old
style). The President will deliver a memorial oration. Come with us
and see the great battlefield, which is a wonderful monument to the
nation’s dead, a beautiful picture itself, and probably you will see
and hear things worth remembering besides. Write to the house,
and I will get your letter when I return in two weeks. But do come.
Yours sincerely,
Edward T. Garrett.