1 programming thinking and method (1) zhao hai 赵海 department of computer science and engineering...

55
1 Programming Thinking and Method (1) Zhao Hai 赵赵 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai @cs.sjtu.edu.cn

Upload: noel-byrd

Post on 24-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

1

Programming Thinking and Method

(1)

Zhao Hai 赵海

Department of Computer Science and EngineeringShanghai Jiao Tong University

 [email protected]

Page 2: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

2

Outline

• Introduction to Computer Science (CS)

• Introduction to Python

Page 3: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

3

Introduction to CS

• What is Computer Science? It is not the study of computers.

“Computers are to computer science what telescopes are

to astronomy.” – E. Dijkstra (May 11, 1930 – August 6,

2002)

He is a Dutch computer scientist and

received the Turing Award for

fundamental contributions to developing

programming languages in 1972 .

Page 4: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

4

Introduction to CS

List of well-known computer scientists

(http://en.wikipedia.org/wiki/List_of_computer_scientists#U)

“Computer science is the study of the foundations of

information and computation and their

implementation and application in computer

systems.” – Wikipedia

It combines science, engineering, and mathematics

into a unique and powerful field.

Page 5: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

5

Introduction to CS

Areas of Computer Science Four areas that it considers crucial to the discipline of

computer science: theory of computation, algorithms and

data structures, programming methodology and

languages, and computer elements and architecture.

Page 6: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

6

Introduction to CS

Theory of computation

focus on answering fundamental questions about what can be

computed and what amount of resources are required to perform

those computations. For example,

Page 7: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

7

Introduction to CS

Computability theory: examines which computational problems

are solvable on various theoretical models of computation.

Wang tiles (or Wang dominoes), designed in 1961 by Wang Hao, are groups of equal size rectangles whose edges are each labeled with a specific color. They provide a simple undecidable decision problem. The above picture shows a set of 13 Wang tiles.

Page 8: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

8

Introduction to CS

Computational complexity theory: studies the time and space

costs associated with different approaches to solving a

computational problem.A representation of the relation among complexity classes, which are subsets of each other.

Page 9: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

9

Introduction to CSComplexity class Model of computation Resource constraint

DTIME(f(n)) Deterministic Turing machine Time f(n)

P Deterministic Turing machine Time poly(n)

EXPTIME Deterministic Turing machine Time 2poly(n)

NTIME(f(n)) Non-deterministic Turing machine Time f(n)

NP Non-deterministic Turing machine Time poly(n)

NEXPTIME Non-deterministic Turing machine Time 2poly(n)

DSPACE(f(n)) Deterministic Turing machine Space f(n)

L Deterministic Turing machine Space O(log n)

PSPACE Deterministic Turing machine Space poly(n)

EXPSPACE Deterministic Turing machine Space 2poly(n)

NSPACE(f(n)) Non-deterministic Turing machine Space f(n)

NL Non-deterministic Turing machine Space O(log n)

NPSPACE Non-deterministic Turing machine Space poly(n)

NEXPSPACE Non-deterministic Turing machine Space 2poly(n)

poly = polynomial

Page 10: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

10

Introduction to CS

Cryptography (密码学 ): studies and applies hiding information

and includes encryption (加密 ) and decryption (解密 ).

The International Data Encryption Algorithm (IDEA) is a block cipher designed by James Massey of ETH Zurich and Xuejia Lai and was first described in 1991.

Page 11: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

11

Introduction to CS

Algorithms and data structures

Algorithms: an effective method for solving a problem expressed

as a finite sequence of instructions. An animation of the quicksort algorithm sorting an array of randomized values.

Page 12: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

12

Introduction to CS

Analysis of algorithms: determines the amount of resources

(such as time and storage) necessary to execute it.

n (list size)

Computer A run-time(in nanoseconds)

Computer B run-time(in nanoseconds)

15 7 ns 100,000 ns

65 32 ns 150,000 ns

250 125 ns 200,000 ns

1,000 500 ns 250,000 ns

Page 13: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

13

Introduction to CS

Data structures: a particular way of storing and organizing data

in a computer so that it can be used efficiently.

A linked list whose nodes contain two fields: an integer value and a link to the next node.

Page 14: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

14

Introduction to CS

Programming methodology and languages

Programming methodology: deals with the analysis, design and

implementation of programs. For instance, one important

methodology involves what is referred to as a "top-down"

approach to analysis, design and implementation.

Page 15: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

15

Introduction to CS

Programming languages: a formal language endowed with

semantics that can be utilized to control the behavior of a

machine, particularly a computer, to perform specific tasks.

Page 16: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

16

Introduction to CS

For example, in 2008 the 10 most cited programming languages

are (in alphabetical order): C, C++, C#, Java, JavaScript, Perl,

PHP, Python, Ruby, and SQL.

Page 17: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

17

Introduction to CS

Computer elements and architecture

Digital logic: may be divided into two classes: combinational

logic, in which the logical outputs are determined by the logical

function being performed and the logical input states at that

particular moment; and sequential logic, in which the outputs also

depend on the prior states of those outputs. Both classes of logic

are used extensively in all digital computers.

Page 18: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

18

Introduction to CS

A B CResult

Logical Equivalent

F F F F A & B & C

F F T F A & B & C

F T F F A & B & C

F T T F A & B & C

T F F T A & B & C

T F T F A & B & C

T T F F A & B & C

T T T T A & B & C

Page 19: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

19

Introduction to CS

NOR gate

INPUTA   B

OUTPUTA NOR B

0 0 1

0 1 0

1 0 0

1 1 0

Page 20: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

20

Introduction to CS

Microarchitecture: (sometimes abbreviated to µarch or uarch) a

given instruction set architecture (ISA) is implemented on a

processor.

Instruction scheduling using a 5 stages pipeline.

Page 21: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

21

Introduction to CS

Multiprocessing: the use of two or more central processing units

(CPUs) within a single computer system. Flynn's Taxonomy of a SImD design: Single Instruction, Multiple Data. Each "PU" (processing unit) does not necessarily correspond to a processor, just some functional unit that can perform processing. The PU's are indicated as such to show relationship between instructions, data, and the processing of the data.

Page 22: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

22

Introduction to CS

In addition to four crucial areas, there are also other important areas described as follows: Software Engineering (SE)

Page 23: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

23

Introduction to CS

Artificial Intelligence (AI)

Machine LearningNatural Language

Processing

Page 24: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

24

Introduction to CS

Computer Networking and Communication

Representative academic library LAN with external access

Page 25: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

25

Introduction to CS

Database Systems (DBS)

A Data Model for Relational Database

Page 26: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

26

Introduction to CS

Parallel Computation

Assume that a task has two independent parts, A and B. B takes roughly 25% of the time of the whole computation. With effort, a programmer may be able to make this part five times faster, but this only reduces the time for the whole computation by a little. In contrast, one may need to perform less work to make part A twice as fast. This will make the computation much faster than by optimizing part B, even though B got a greater speed-up (5× versus 2×).

Page 27: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

27

Introduction to CS

Distributed Computation

(a)–(b) A distributed system.(c) A parallel system.

Page 28: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

28

Introduction to CS

Computer-Human Interaction

Wacom Pen Tablet with Pen and mouse, Intuos 3 A5

Page 29: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

29

Introduction to CS

Computer Graphics

A 3D projection of a 5-cell performing a double rotation about two orthogonal planes.

Page 30: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

30

Introduction to CS

Operating Systems (OS)

A typical Operating System placement on computer usage

Page 31: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

31

Introduction to CS

Numerical and Symbolic Computation

3x3 + 4 = 28.

Subtract 4 3x3 = 24.

Divide by 3 x3 = 8.

Take cube roots

x = 2.

numerical computation symbolic computation

Page 32: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

32

Introduction to CS

Summary Computer science is the study of the foundations of

information and computation and their implementation

and application in computer systems.

Major discipline fields: Major fields of computer science

Mathematical Foundations

Mathematical logic · Set theory · Number theory · Graph theory · Type theory · Category theory · Numerical analysis  · Information theory

Page 33: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

33

Introduction to CS

Theory of ComputationAutomata theory · Computability theory · Computational complexity theory · Quantum computing theory

Algorithms and Data Structures Analysis of algorithms · Algorithm design · Computational geometry

Programming Languages and Compilers

Parsers · Interpreters · Procedural programming · Object-oriented programming · Functional programming · Logic programming · Programming paradigms

Concurrent, Parallel, and Distributed Systems

Multiprocessing · Grid computing · Concurrency control

Page 34: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

34

Introduction to CS

Software Engineering

Requirements analysis · Software design · Computer programming · Formal methods · Software testing · Software development process

System Architecture Computer architecture · Computer organization · Operating systems

Telecommunication & Networking Computer audio · Routing · Network topology · Cryptography

Databases

Database management systems · Relational databases · SQL · Transactions · Database indexes · Data mining

Page 35: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

35

Introduction to CS

Artificial Intelligence

Automated reasoning · Computational linguistics · Computer vision · Evolutionary computation · Expert systems · Machine learning · Natural language processing · Robotics

Computer Graphics Visualization · Computer animation · Image processing

Human–Computer InteractionComputer accessibility · User interfaces · Wearable computing · Ubiquitous computing · Virtual reality

Scientific computing

Artificial life · Bioinformatics · Cognitive science · Computational chemistry · Computational neuroscience · Computational physics · Numerical algorithms · Symbolic mathematics

Page 36: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

36

Introduction to CS

Reference

Nell Dale, John Lewis. Computer Science

Illuminated. Jones and Bartlett Publishers. 2002.

ISBN 0-7637-1760-6.

Page 37: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

37

Introduction to Python

What is Python Programming Language? Python is a general-purpose high-level programming

language whose design philosophy emphasizes code

readability.

Python supports multiple programming paradigms,

primarily but not limited to object oriented, imperative

and, to a lesser extent, functional programming styles.

Page 38: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

38

Python aims to combine "remarkable power with very

clear syntax", and its standard library is large and

comprehensive.

Its use of indentation for block delimiters is unusual

among popular programming languages.

Introduction to Python

Page 39: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

39

Development of Python Python was conceived in the late 1980s and its

implementation was started in December 1989 by Guido

van Rossum at CWI (Centrum Wiskunde & Informatica)

in the Netherlands.

Introduction to Python

Page 40: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

40

Python 2.0 was released on 16 October 2000, with many

major new features including a full garbage collector and

support for Unicode.

Python 3.0, a major, backwards-incompatible release with

Python 2.x, was released on 3 December 2008 after a long

period of testing.

Many of its major features have been backported to the

backwards-compatible Python 2.7.

Introduction to Python

Page 41: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

41

Advantages of Python It's Object-Oriented: Python is an object-oriented

language, from the ground up. Its class model

supports advanced notions such as polymorphism,

operator overloading, and multiple inheritance.

It's Free: Python is freeware — something which has

lately been come to be called open source software.

Introduction to Python

Page 42: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

42

It's Portable: Python is written in portable ANSI C, and

compiles and runs on virtually every major platform in use

today.

It's Powerful: Its tool set places it between traditional

scripting languages (such as Tcl, Scheme, and Perl), and

systems languages (such as C, C++, and Java).

Introduction to Python

Page 43: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

43

It's Mixable: Python programs can be easily "glued" to

components written in other languages.

It's Easy to Use: as with other interpreted languages,

Python executes programs immediately, which makes for

both an interactive programming experience and rapid

turnaround after program changes.

Introduction to Python

Page 44: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

44

It's Easy to Learn: In fact, you can expect to be

coding significant Python programs in a matter of

days (and perhaps in just hours, if you're already

an experienced programmer).

Introduction to Python

Page 45: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

45

The latest version for Python is 2.75 and 3.3.2 up to now (2013.09.10).

Development Environment of Python

Python (command line), IDLE and PythonWin

It is an interactive environment which reads a high-level program and executes it, and

processes the program a little at a time (statement by statement) by calling the Python

interpreter.

Note : Compare with a compiler which reads the program and translates it completely

before the program starts running.

Introduction to Python

Page 46: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

46

Python under Windows

Introduction to Python

Page 47: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

47

The First Example (interactive mode)

Run Python (command line) and then see system information:

Python 3.1.2 (r312:79149, Mar 20 2010, 22:55:39) [MSC v.1500 64

bit (AMD 64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

>>>

Input a statement after the prompt symbol and return:

>>> print (“Hello, Everybody!”)

Introduction to Python

Page 48: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

48

The string is displayed on the screen:

Hello, Everybody!

Introduction to Python

Page 49: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

49

The Second Example (module or script mode) A module file is a text file, and you can create one using

any environment for editing text. The .py extension of the

text file indicates that this is a Python module.

The advantages of module or script mode is that we can

saved it on a disk so that it can be used over and over

again. On the other hand, it can be run like a compiled

program. Especially it is suitable for large program.

Introduction to Python

Page 50: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

50

A module file called chaos.py is shown as follows.

Chaos theory (混沌理论 ) is a field of study in

mathematics, physics, economics and philosophy studying

the behavior of dynamical systems that are highly

sensitive to initial conditions.

Introduction to Python

Page 51: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

51

# File: chaos.py

# A simple program illustrating chaotic behavior.

def main():

print ("This program illustrates a chaotic function“)

x = input("Enter a number between 0 and 1: ")

for i in range(10):

x = 3.9 * x * (1 - x)

print (x)

main()

Introduction to Python

Page 52: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

52

You can use Run or Import function under PythonWin,

and then select a module’s file name (chaos.py).

The running result is shown on the screen:

This program illustrates a chaotic function

Enter a number between 0: .25

0.73125

0.76644140625

0.698135010439

0.82189581879

0.570894019197

Introduction to Python

Page 53: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

53

0.955398748364

0.166186721954

0.540417912062

0.9686289303

0.118509010176

Introduction to Python

Page 54: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

54

Summary Python is a general-purpose high-level programming

language.

Python supports multiple programming paradigms,

primarily but not limited to object oriented, imperative,

and functional programming styles.

Python aims to combine "remarkable power with very

clear syntax", and its standard library is large and

comprehensive.

Introduction to Python

Page 55: 1 Programming Thinking and Method (1) Zhao Hai 赵海 Department of Computer Science and Engineering Shanghai Jiao Tong University zhaohai@cs.sjtu.edu.cn zhaohai@cs.sjtu.edu.cn

55

Its use of indentation for block delimiters is unusual

among popular programming languages.

Python was conceived in the late 1980s and its

implementation was started in December 1989 by Guido

van Rossum at CWI in the Netherlands.

Python’s advantages include object-oriented, free,

portable, powerful, mixable, easy to use, and easy to learn

properties.

PythonWin 2.6.4 is a perfect development environment

for Python under Windows.

Introduction to Python