没有合适的资源?快使用搜索试试~ 我知道了~
首页Python编程入门:通向问题解决的艺术
Python编程入门:通向问题解决的艺术
需积分: 9 5 下载量 113 浏览量
更新于2024-07-18
收藏 13.49MB PDF 举报
"《使用Python进行计算与编程入门》是一本基于麻省理工学院自2006年起每年两次开设的课程编写的教材。该课程旨在为没有或仅有少量编程经验但对解决问题的计算方法感兴趣的学员提供基础知识。课程的目标是为大多数学生提供广泛的而不是深入的计算机科学入门,通过简短介绍多种主题,使他们对如何运用计算实现目标有所了解,但并非单纯的计算欣赏课程,而是一门富有挑战且严格的课程,学生们将花费大量时间和精力学习如何让计算机服务于他们的需求。 本书的主要目的是帮助读者掌握有效的计算技术应用技巧。读者应学会将计算思维模式应用于问题定义,以及以计算方式引导从数据中提取信息的过程。通过阅读本书,你将收获的核心能力是计算问题解决的艺术。作者约翰·G·古塔格(John V. Guttag)修订并扩展了这本书,使之成为学习者进入计算科学世界的一把钥匙,特别是对于那些仅有的计算机科学课程来说,这将是一个宝贵的学习资源。 课程内容涵盖了Python语言的基础,包括但不限于数据结构、算法、函数设计、面向对象编程、网络编程和数据分析等方面。通过实例和练习,学生将逐步熟悉编程逻辑,培养解决问题的能力。此外,书中强调理论与实践相结合,鼓励读者动手实践,以实际项目的形式检验所学知识。 《使用Python进行计算与编程入门》不仅适合初学者,也适合有一定基础的开发者提升其编程技能和理解计算思维。无论你是希望在计算机科学领域进一步探索,还是寻求在实际工作中更高效地利用计算工具,这本书都是一个不可或缺的参考资源。版权方面,所有内容未经许可不得以任何形式的电子或机械手段复制,如有需要,请遵循出版社的版权规定。该书在全球范围内印刷,版权登记在案,购买时可享受批量折扣。"
资源详情
资源推荐
ACKNOWLEDGMENTS
This book grew out of a set of lecture notes that I prepared while teaching an
undergraduate course at MIT. The course, and therefore this book, benefited
from suggestions from faculty colleagues (especially Eric Grimson, Srinivas
Devadas, and Fredo Durand), teaching assistants, and the students who took
the course.
The process of transforming my lecture notes into a book proved far more
onerous than I had expected. Fortunately, this misguided optimism lasted long
enough to keep me from giving up. The encouragement of colleagues and family
also helped keep me going.
Eric Grimson, Chris Terman, and David Guttag provided vital help. Eric, who is
MIT’s Chancellor, managed to find the time to read almost the entire book with
great care. He found numerous errors (including an embarrassing, to me,
number of technical errors) and pointed out places where necessary
explanations were missing. Chris also read parts of the manuscript and
discovered errors. He also helped me battle Microsoft Word, which we
eventually persuaded to do most of what we wanted. David overcame his
aversion to computer science, and proofread multiple chapters.
Preliminary versions of this book were used in the MIT course 6.00 and the MITx
course 6.00x. A number of students in these courses pointed out errors. One
6.00x student, J.C. Cabrejas, was particularly helpful. He found a large number
of typos, and more than a few technical errors.
Like all successful professors, I owe a great deal to my graduate students. The
photo on the back cover of this book depicts me supporting some of my current
students. In the lab, however, it is they who support me. In addition to doing
great research (and letting me take some of the credit for it), Guha
Balakrishnan, Joel Brooks, Ganeshapillai Gartheeban, Jen Gong, Yun Liu,
Anima Singh, Jenna Wiens, and Amy Zhao all provided useful comments on this
manuscript.
I owe a special debt of gratitude to Julie Sussman, P.P.A. Until I started working
with Julie, I had no idea how much difference an editor could make. I had
worked with capable copy editors on previous books, and thought that was what
I needed for this book. I was wrong. I needed a collaborator who could read the
book with the eyes of a student, and tell me what needed to be done, what
should be done, and what could be done if I had the time and energy to do it.
Julie buried me in “suggestions” that were too good to ignore. Her combined
command of both the English language and programming is quite remarkable.
Finally, thanks to my wife, Olga, for pushing me to finish and for pitching in at
critical times.
1 GETTING STARTED
A computer does two things, and two things only: it performs calculations and it
remembers the results of those calculations. But it does those two things
extremely well. The typical computer that sits on a desk or in a briefcase
performs a billion or so calculations a second. It’s hard to image how truly fast
that is. Think about holding a ball a meter above the floor, and letting it go. By
the time it reaches the floor, your computer could have executed over a billion
instructions. As for memory, a typical computer might have hundreds of
gigabytes of storage. How big is that? If a byte (the number of bits, typically
eight, required to represent one character) weighed one ounce (which it doesn’t),
100 gigabytes would weigh more than 3,000,000 tons. For comparison, that’s
roughly the weight of all the coal produced in a year in the U.S.
For most of human history, computation was limited by the speed of calculation
of the human brain and the ability to record computational results with the
human hand. This meant that only the smallest problems could be attacked
computationally. Even with the speed of modern computers, there are still
problems that are beyond modern computational models (e.g., understanding
climate change), but more and more problems are proving amenable to
computational solution. It is our hope that by the time you finish this book, you
will feel comfortable bringing computational thinking to bear on solving many of
the problems you encounter during your studies, work, and even everyday life.
What do we mean by computational thinking?
All knowledge can be thought of as either declarative or imperative. Declarative
knowledge is composed of statements of fact. For example, “the square root of x
is a number y such that y
*
y = x.” This is a statement of fact. Unfortunately it
doesn’t tell us how to find a square root.
Imperative knowledge is “how to” knowledge, or recipes for deducing
information. Heron of Alexandria was the first to document a way to compute
the square root of a number.
2
His method can be summarized as:
• Start with a guess, g.
• If g
*
g is close enough to x, stop and say that g is the answer.
• Otherwise create a new guess by averaging g and x/g, i.e., (g + x/g)/2.
• Using this new guess, which we again call g, repeat the process until g
*
g
is close enough to x.
2
Many believe that Heron was not the inventor of this method, and indeed there is some
evidence that it was well known to the ancient Babylonians.
2 Chapter 1. Getting Started
Consider, for example, finding the square root of 25.
1. Set g to some arbitrary value, e.g., 3.
2. We decide that 3
*
3 = 9 is not close enough to 25.
3. Set g to (3 + 25/3)/2 = 5.67.
3
4. We decide that 5.67
*
5.67 = 32.15 is still not close enough to 25.
5. Set g to (5.67 + 25/5.67)/2 = 5.04
6. We decide that 5.04
*
5.04 = 25.4 is close enough, so we stop and declare 5.04
to be an adequate approximation to the square root of 25.
Note that the description of the method is a sequence of simple steps, together
with a flow of control that specifies when each step is to be executed. Such a
description is called an algorithm.
4
This algorithm is an example of a guess-
and-check algorithm. It is based on the fact that it is easy to check whether or
not a guess is a good one.
A bit more formally, an algorithm is a finite list of instructions that describe a
computation that when executed on a provided set of inputs will proceed
through a set of well-defined states and eventually produce an output.
An algorithm is a bit like a recipe from a cookbook:
1. Put custard mixture over heat.
2. Stir.
3. Dip spoon in custard.
4. Remove spoon and run finger across back of spoon.
5. If clear path is left, remove custard from heat and let cool.
6. Otherwise repeat.
It includes some tests for deciding when the process is complete, as well as
instructions about the order in which to execute instructions, sometimes
jumping to some instruction based on a test.
So how does one capture this idea of a recipe in a mechanical process? One way
would be to design a machine specifically intended to compute square roots.
Odd as this may sound, the earliest computing machines were, in fact, fixed-
program computers, meaning they were designed to do very specific things, and
were mostly tools to solve a specific mathematical problem, e.g., to compute the
trajectory of an artillery shell. One of the first computers (built in 1941 by
Atanasoff and Berry) solved systems of linear equations, but could do nothing
else. Alan Turing’s bombe machine, developed during World War II, was
designed strictly for the purpose of breaking German Enigma codes. Some very
simple computers still use this approach. For example, a four-function
calculator is a fixed-program computer. It can do basic arithmetic, but it cannot
3
For simplicity, we are rounding results.
4
The word “algorithm” is derived from the name of the Persian mathematician
Muhammad ibn Musa al-Khwarizmi.
Chapter 1. Getting Started 3
be used as a word processor or to run video games. To change the program of
such a machine, one has to replace the circuitry.
The first truly modern computer was the Manchester Mark 1.
5
It was
distinguished from its predecessors by the fact that it was a stored-program
computer. Such a computer stores (and manipulates) a sequence of
instructions, and has a set of elements that will execute any instruction in that
sequence. By creating an instruction-set architecture and detailing the
computation as a sequence of instructions (i.e., a program), we make a highly
flexible machine. By treating those instructions in the same way as data, a
stored-program machine can easily change the program, and can do so under
program control. Indeed, the heart of the computer then becomes a program
(called an interpreter) that can execute any legal set of instructions, and thus
can be used to compute anything that one can describe using some basic set of
instructions.
Both the program and the data it manipulates reside in memory. Typically there
is a program counter that points to a particular location in memory, and
computation starts by executing the instruction at that point. Most often, the
interpreter simply goes to the next instruction in the sequence, but not always.
In some cases, it performs a test, and on the basis of that test, execution may
jump to some other point in the sequence of instructions. This is called flow of
control, and is essential to allowing us to write programs that perform complex
tasks.
Returning to the recipe metaphor, given a fixed set of ingredients a good chef
can make an unbounded number of tasty dishes by combining them in different
ways. Similarly, given a small fixed set of primitive elements a good programmer
can produce an unbounded number of useful programs. This is what makes
programming such an amazing endeavor.
To create recipes, or sequences of instructions, we need a programming
language in which to describe these things, a way to give the computer its
marching orders.
In 1936, the British mathematician Alan Turing described a hypothetical
computing device that has come to be called a Universal Turing Machine. The
machine had an unbounded memory in the form of tape on which one could
write zeros and ones, and some very simple primitive instructions for moving,
reading, and writing to the tape. The Church-Turing thesis states that if a
function is computable, a Turing Machine can be programmed to compute it.
The “if” in the Church-Turing thesis is important. Not all problems have
computational solutions. For example, Turing showed that it is impossible to
write a program that given an arbitrary program, call it P, prints true if and only
if P will run forever. This is known as the halting problem.
5
This computer was built at the University of Manchester, and ran its first program in
1949. It implemented ideas previously described by John von Neumann and was
anticipated by the theoretical concept of the Universal Turing Machine described by Alan
Turing in 1936.
剩余314页未读,继续阅读
Great_Li_Xin
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AirKiss技术详解:无线传递信息与智能家居连接
- Hibernate主键生成策略详解
- 操作系统实验:位示图法管理磁盘空闲空间
- JSON详解:数据交换的主流格式
- Win7安装Ubuntu双系统详细指南
- FPGA内部结构与工作原理探索
- 信用评分模型解析:WOE、IV与ROC
- 使用LVS+Keepalived构建高可用负载均衡集群
- 微信小程序驱动餐饮与服装业创新转型:便捷管理与低成本优势
- 机器学习入门指南:从基础到进阶
- 解决Win7 IIS配置错误500.22与0x80070032
- SQL-DFS:优化HDFS小文件存储的解决方案
- Hadoop、Hbase、Spark环境部署与主机配置详解
- Kisso:加密会话Cookie实现的单点登录SSO
- OpenCV读取与拼接多幅图像教程
- QT实战:轻松生成与解析JSON数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功