This page intentionally left blank Python for Software Design



tải về 1.38 Mb.
Chế độ xem pdf
trang5/83
Chuyển đổi dữ liệu13.08.2023
Kích1.38 Mb.
#55046
1   2   3   4   5   6   7   8   9   ...   83
- Python for Software Design How to Think Like a Computer Scientist-Cambridge University Press (2009)

script mode. In interactive mode, you type Python programs and the interpreter
prints the result:
>>> 1 + 1
2
The chevron, >>>, is the prompt the interpreter uses to indicate that it is ready. If
you type 1 + 1, the interpreter replies 2.
Alternatively, you can store code in a file and use the interpreter to execute the
contents of the file, which is called a script. By convention, Python scripts have
names that end with .py.
To execute the script, you have to tell the interpreter the name of the file. In a UNIX
command window, you would type python dinsdale.py. In other development
environments, the details of executing scripts are different. You can find instructions
for your environment at the Python Website python.org.


1.3 What is Debugging
3
Working in interactive mode is convenient for testing small pieces of code because
you can type and execute them immediately. But for anything more than a few lines,
you should save your code as a script so you can modify and execute it in the future.
1.2
WHAT IS A PROGRAM?
program is a sequence of instructions that specifies how to perform a computa-
tion. The computation might be something mathematical, such as solving a system of
equations or finding the roots of a polynomial, but it can also be a symbolic compu-
tation, such as searching for and replacing text in a document or (strangely enough)
compiling a program.
The details look different in different languages, but a few basic instructions appear
in just about every language:
input: Get data from the keyboard, a file, or some other device.
output: Display data on the screen or send data to a file or other device.
math: Perform basic mathematical operations like addition and multiplication.
conditional execution: Check for certain conditions and execute the appropriate
sequence of statements.
repetition: Perform some action repeatedly, usually with some variation.
Believe it or not, that’s pretty much all there is to it. Every program you’ve ever used,
no matter how complicated, is made up of instructions that look pretty much like
these. So you can think of programming as the process of breaking a large, complex
task into smaller and smaller subtasks until the subtasks are simple enough to be
performed with one of these basic instructions.
That may be a little vague, but we will come back to this topic when we talk about

tải về 1.38 Mb.

Chia sẻ với bạn bè của bạn:
1   2   3   4   5   6   7   8   9   ...   83




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương