没有合适的资源?快使用搜索试试~ 我知道了~
首页Python Programming: An Introduction to Computer Science
Python Programming: An Introduction to Computer Science
5星 · 超过95%的资源 需积分: 9 180 下载量 48 浏览量
更新于2023-06-30
评论
收藏 5.45MB PDF 举报
Python Programming: An Introduction to Computer Science by John M. Zelle, 517 pages, December 2003 第一版完整版
资源详情
资源评论
资源推荐
PYTHON PROGRAMMING
AN INTRODUCTION TO COMPUTER SCIENCE
John M. Zelle
Wartburg College
Franklin, Beedle & Associates, Inc. 8536 SW St. Helens Drive, Suite D Wilsonville, Oregon 97070 503/682-7668
www.fbeedle.com
President and Publisher Jim Leisy (jimleisy@fbeedle.com)
Production TomSumner
Dean Lake
Cover Ian Shadburne
Marketing Christine Collier
Order Processing Krista Brown
Printed in the U.S.A.
Names of all products herein are used for identification purposes only and are trade-
marks and/or registered trademarks of their respective owners. Franklin, Beedle & Asso-
ciates, Inc., makes no claim of ownership or corporate association with the products or
companies that own them.
©2004 Franklin, Beedle & Associates Incorporated. No part of this book may be repro-
duced, stored in a retrieval system, transmitted, or transcribed, in any form or by any
means—electronic, mechanical, telepathic, photocopying, recording, or otherwise—with-
out prior written permission of the publisher. Requests for permission should be ad-
dressed as follows:
Rights and Permissions
Franklin, Beedle & Associates, Incorporated
8536 SW St. Helens Drive, Suite D
Wilsonville, Oregon 97070
Library of Congress Cataloging-in-Publication data may be obtained from the publisher.
Contents
Foreword ..............................................................................................................................ix
Preface ................................................................................................................................. x
Chapter 1 Computers and Programs 1
1.1 The Universal Machine ............................................................................................. 1
1.2 Program Power ........................................................................................................ 3
1.3 What is Computer Science? ...................................................................................... 3
1.4 Hardware Basics ....................................................................................................... 5
1.5 Programming Languages .......................................................................................... 6
1.6 The Magic of Python ............................................................................................... 9
1.7 Inside a Python Program .........................................................................................14
1.8 Chaos and Computers .............................................................................................17
1.9 Chapter Summary ...................................................................................................18
1.10 Exercises .................................................................................................................20
Chapter 2 Writing Simple Programs 25
2.1 The Software Development Process ...................................................................... 25
2.2 Example Program: Temperature Converter .............................................................. 26
2.3 Elements of Programs ............................................................................................. 29
2.3.1 Names ........................................................................................................29
2.3.2 Expressions ................................................................................................. 30
2.4 Output Statements .................................................................................................31
2.5 Assignment Statements ......................................................................................... 33
2.5.1 Simple Assignment .....................................................................................33
2.5.2 Assigning Input...........................................................................................35
2.5.3 Simultaneous Assignment ........................................................................... 36
2.6 Definite Loops....................................................................................................... 39
2.7 Example Program: Future Value ............................................................................ 42
Contents
iv
2.8 Chapter Summary ...................................................................................................45
2.9 Exercises .................................................................................................................46
Chapter 3 Computing with Numbers 51
3.1 Numeric Data Types ............................................................................................... 51
3.2 Using the Math Library ...........................................................................................55
3.3 Accumulating Results: Factorial ............................................................................... 58
3.4 The Limits of Int ..................................................................................................... 61
3.5 Handling Large Numbers: Long Ints ....................................................................... 64
3.6 Type Conversions ....................................................................................................66
3.7 Chapter Summary ...................................................................................................68
3.8 Exercises ............................................................................................................... 69
Chapter 4 Computing with Strings 77
4.1 The String Data Type ........................................................................................... 77
4.2 Simple String Processing ...................................................................................... 82
4.3 Strings, Lists, and Sequences ................................................................................ 85
4.4 Strings and Secret Codes ...................................................................................... 87
4.4.1 String Representation .............................................................................. 87
4.4.2 Programming an Encoder ......................................................................... 89
4.4.3 Programming a Decoder ........................................................................... 90
4.4.4 Other String Operations ........................................................................... 94
4.4.5 From Encoding to Encryption ................................................................... 95
4.5 Input/Output as String Manipulation .................................................................... 97
4.5.1 Example Application: Date Conversion ..................................................... 97
4.5.2 String Formatting .................................................................................. 102
4.5.3 Better Change Counter .......................................................................... 104
4.6 File Processing ..................................................................................................... 106
4.6.1 Multi-Line Strings .................................................................................... 106
4.6.2 File Processing ...................................................................................... 107
4.6.3 Example Program: Batch Usernames ....................................................... 111
4.6.4 Coming Attraction: Objects ................................................................... 112
4.7 Chapter Summary ................................................................................................. 113
4.8 Exercises .............................................................................................................. 115
Chapter 5 Objects and Graphics 123
5.1 Overview ............................................................................................................ 123
5.2 The Object of Objects .......................................................................................... 124
5.3 Simple Graphics Programming .............................................................................. 125
5.4 Using Graphical Objects ..................................................................................... 129
5.5 Graphing Future Value ......................................................................................... 135
5.6 Choosing Coordinates ........................................................................................... 143
5.7 Interactive Graphics .............................................................................................. 146
5.7.1 Getting Mouse Clicks ............................................................................... 146
5.7.2 Handling Textual Input ............................................................................ 148
Contents
v
5.8 Graphics Module Reference .................................................................................. 151
5.8.1 GraphWin Objects ................................................................................... 151
5.8.2 Graphics Objects ................................................................................... 152
5.8.3 Entry Objects .......................................................................................... 155
5.8.4 Displaying Images .................................................................................... 155
5.8.5 Generating Colors .................................................................................... 156
5.9 Chapter Summary ................................................................................................. 156
5.10 Exercises .............................................................................................................. 157
Chapter 6 Defining Functions 165
6.1 The Function of Functions ................................................................................... 165
6.2 Functions, Informally ............................................................................................ 167
6.3 Future Value with a Function ............................................................................. 171
6.4 Functions and Parameters: The Details ................................................................. 173
6.5 Getting Results from a Function ........................................................................... 177
6.5.1 Functions That Return Values ................................................................. 177
6.5.2 Functions that Modify Parameters ......................................................... 181
6.6 Functions and Program Structure ......................................................................... 187
6.7 Chapter Summary ................................................................................................. 191
6.8 Exercises .............................................................................................................. 191
Chapter 7 Decision Structures 199
7.1 Simple Decisions ................................................................................................... 199
7.1.1 Example: Temperature Warnings ............................................................ 200
7.1.2 Forming Simple Conditions .................................................................... 202
7.1.3 Example: Conditional Program Execution ................................................. 204
7.2 Two-Way Decisions ............................................................................................... 206
7.3 Multi-Way Decisions............................................................................................. 210
7.4 Exception Handling ............................................................................................... 213
7.5 Study in Design: Max of Three ............................................................................. 217
7.5.1 Strategy 1: Compare Each to All ............................................................ 218
7.5.2 Strategy 2: Decision Tree ......................................................................... 220
7.5.3 Strategy 3: Sequential Processing .......................................................... 221
7.5.4 Strategy 4: Use Python.......................................................................... 223
7.5.5 Some Lessons .......................................................................................... 224
7.6 Chapter Summary ................................................................................................. 225
7.7 Exercises .............................................................................................................. 225
Chapter 8 Loop Structures and Booleans 233
8.1 For Loops: A Quick Review .................................................................................. 233
8.2 Indefinite Loops ................................................................................................... 235
8.3 Common Loop Patterns ....................................................................................... 237
8.3.1 Interactive Loops ................................................................................... 237
8.3.2 Sentinel Loops ......................................................................................... 239
8.3.3 File Loops ................................................................................................ 242
剩余534页未读,继续阅读
gstrangtw
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论12