Example: barber

How to Think Like a Computer Scientist: Learning with ...

How to Think like a ComputerScientist: Learning with Python 3 DocumentationRelease 3rd EditionPeter Wentworth, Jeffrey Elkner, allen B. downey and Chris MeyersApr 17, 2020 Contents1 The way of the program32 Variables, expressions and statements113 Program Flow234 Functions635 Data Types916 Numpy1337 Files1398 Modules1459 More datatypes15710 Recursion16111 Classes and Objects17512 Exceptions21313 Fitting21914 PyGame22515 Plotting data with matplotlib24516 Copyright Notice25717 Contributions259A Modules263B More datatypes275C Recursion279iD Classes and Objects293E Exceptions331F Fitting337G PyGame343H Plotting data with matplotlib363 Index375iiHow to Think like a Computer scientist : Learning with Python 3 Documentation, Release 3rdEdition3rd Edition (Using Python )by Jeffrey Elkner, Peter Wentworth, allen B.

Allen B. Downey and Chris Meyers Apr 17, 2020. Contents 1 The way of the program 3 2 Variables, expressions and statements11 3 Program Flow 23 4 Functions 63 5 Data Types 91 6 Numpy 133 7 Files 139 8 Modules 145 9 More datatypes 157 10 Recursion 161 11 Classes and Objects 175 12 Exceptions 213

Tags:

  Computer, Scientist, Think, Allen, Like, Think like a computer scientist, Downey

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of How to Think Like a Computer Scientist: Learning with ...

1 How to Think like a ComputerScientist: Learning with Python 3 DocumentationRelease 3rd EditionPeter Wentworth, Jeffrey Elkner, allen B. downey and Chris MeyersApr 17, 2020 Contents1 The way of the program32 Variables, expressions and statements113 Program Flow234 Functions635 Data Types916 Numpy1337 Files1398 Modules1459 More datatypes15710 Recursion16111 Classes and Objects17512 Exceptions21313 Fitting21914 PyGame22515 Plotting data with matplotlib24516 Copyright Notice25717 Contributions259A Modules263B More datatypes275C Recursion279iD Classes and Objects293E Exceptions331F Fitting337G PyGame343H Plotting data with matplotlib363 Index375iiHow to Think like a Computer scientist : Learning with Python 3 Documentation, Release 3rdEdition3rd Edition (Using Python )by Jeffrey Elkner, Peter Wentworth, allen B.

2 downey , and Chris Meyersillustrated by Dario Mitchell Copyright Notice Contributor List Chapter 1 The way of the program Chapter 2 Variables, expressions, and statements Chapter 3 Program Flow Chapter 4 Functions Chapter 5 Datatypes Chapter 6 Numpy Chapter 7 File I/O Appendix AWriting Your Own Modules Appendix BMore datatypes Appendix CRecursion Appendix DObject Oriented Programming Appendix EExceptions Appendix FFitting and Scientific Data Handling Appendix GPyGame Appendix HPlotting with matplotlib GNU Free Document LicenseContents1 How to Think like a Computer scientist : Learning with Python 3 Documentation, Release 3rdEdition2 ContentsCHAPTER1 The way of the programThe goal of this book is to teach you to Think like a Computer scientist .

3 This way of thinking combines some of thebest features of mathematics, engineering, and natural science. like mathematicians, Computer scientists use formallanguages to denote ideas (specifically computations). like engineers, they design things, assembling components intosystems and evaluating tradeoffs among alternatives. like scientists, they observe the behavior of complex systems,form hypotheses, and test single most important skill for a Computer scientist isproblem solving. Problem solving means the ability toformulate problems, Think creatively about solutions, and express a solution clearly and accurately. As it turns out, theprocess of Learning to program is an excellent opportunity to practice problem-solving skills. That s why this chapteris called, The way of the one level, you will be Learning to program, a useful skill by itself.

4 On another level, you will use programming asa means to an end. As we go along, that end will become The Python programming languageThe programming language you will be Learning is Python. Python is an example of ahigh-level language; otherhigh-level languages you might have heard of are C++, PHP, Pascal, C#, and you might infer from the name high-level language, there are alsolow-level languages, sometimes referred to asmachine languages or assembly languages. Loosely speaking, computers can only execute programs written in low-level languages. Thus, programs written in a high-level language have to be translated into something more suitablebefore they can all programs are written in high-level languages because of their advantages.

5 It is much easier to program in ahigh-level language so programs take less time to write, they are shorter and easier to read, and they are more likelyto be correct. Second, high-level languages areportable, meaning that they can run on different kinds of computerswith few or no engine that translates and runs Python is called thePython Interpreter: There are two ways to use it:immediatemodeandscript mode. In immediate mode, you type Python expressions into the Python Interpreter window, and theinterpreter immediately shows the result:3 How to Think like a Computer scientist : Learning with Python 3 Documentation, Release 3rdEditionThe>>>is called thePython prompt. The interpreter uses the prompt to indicate that it is ready for instructions.

6 Wetyped2 + 2, and the interpreter evaluated our expression, and replied4, and on the next line it gave a new prompt,indicating that it is ready for more , you can write a program in a file and use the interpreter to execute the contents of the file. Such a file iscalled ascript. Scripts have the advantage that they can be saved to disk, printed, and so directly in the interpreter is convenient for testing short bits of code because you get immediate of it as scratch paper used to help you work out problems. Anything longer than a few lines should be put intoa you are writing a script you need something like a text editor. With this we mean a program on your computerthat changes text files, not something that also does layout like a word processor such as Microsoft Word or LibreOfficeWriter.

7 A few examples of text editors are Notepad, Notepad++, vim, emacs and Python (and many other programming languages) there are programs that include both a text editor and a way to in-teract with the interpreter. We call these development environments (sometimes Integrated Development Environmentor IDE). For Python these can include (among many others) Spyder, Thonny or IDLE. There are also developmentenvironments that run in your browser. One example of this is Jupyter choice of development environment is quite personal, but if you are following a course based on this book theteacher will probably recommend one. That recommendation is handy to follow if you need help using the important thing to remember is that Python itself does not care in what editor you write your code.

8 As long asyou write correct syntax (with the right tabs and spaces) Python can run your program. The editor is only there to What is a program?Aprogramis a sequence of instructions that specifies how to perform a computation. The computation might besomething mathematical, such as solving a system of equations or finding the roots of a polynomial, but it can alsobe a symbolic computation, such as searching and replacing text in a document or (strangely enough) compiling details look different in different languages, but a few basic instructions appear in just about every language:inputGet data from the keyboard, a file, or some other device such as a data on the screen or send data to a file or other device such as a basic mathematical operations like addition and executionCheck for certain conditions and execute the appropriate sequence of some action repeatedly, usually with some it or not, that s pretty much all there is to it.

9 Every program you ve ever used, no matter how complicated,is made up of instructions that look more or less like these. Thus, we can describe programming as the process of4 Chapter 1. The way of the programHow to Think like a Computer scientist : Learning with Python 3 Documentation, Release 3rdEditionbreaking a large, complex task into smaller and smaller subtasks until the subtasks are simple enough to be performedwith sequences of these basic may be a little vague, but we will come back to this topic later when we talk What is debugging?Programming is a complex process, and because it is done by human beings, it often leads to errors. Programmingerrors are calledbugsand the process of tracking them down and correcting them is calleddebugging.

10 Use of thetermbugto describe small engineering difficulties dates back to at least 1889, when Thomas Edison had a bug withhis kinds of errors can occur in a program: syntax errors, runtime errors, and semantic errors. It is useful todistinguish between them in order to track them down more Syntax errorsPython can only execute a program if the program is syntactically correct; otherwise, the process fails and returns anerror to the structure of a program and the rules about that structure. For example, in English,a sentence must begin with a capital letter and end with a period. this sentence contains asyntax error. So does thisoneFor most readers, a few syntax errors are not a significant problem, which is why we can read the poetry of E.


Related search queries