Monday, April 19, 2021

Think Like a Computer; Scientist: Learning with Python

 Step by step instructions to Think Like a Computer 


Researcher: Learning with Python 3 


Documentation 


Apr 17, 2020 


Substance 


1 The method of the program


2 Variables, articulations and statements 11 


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 


13 Fitting 219 


14 PyGame 225 


15 Plotting information with matplotlib 245 


16 Copyright Notice 257 


17 Contributions 259 


A Modules 263 


B More datatypes 275 


C Recursion 279 


D Classes and Objects 293 


E Exceptions 331 


F Fitting 337 


G PyGame 343 


H Plotting information with matplotlib 363 


File 375 


Step by step instructions to Think Like a Computer Scientist: Learning with Python 3 Documentation, Release third 


Release 


third Edition (Using Python 3.x) 


by Jeffrey Elkner, Peter Wentworth, Allen B. Downey, and Chris Meyers represented by Dario Mitchell 


• Copyright Notice 


• Contributor List 


• Chapter 1 The method of the program 


• Chapter 2 Variables, articulations, and explanations 


• Chapter 3 Program Flow 


• Chapter 4 Functions 


• Chapter 5 Datatypes 


• Chapter 6 Numpy 


• Chapter 7 File I/O 


• Appendix A Writing Your Own Modules 


• Appendix B More datatypes 


• Appendix C Recursion 


• Appendix D Object Oriented Programming 


• Appendix E Exceptions 


• Appendix F Fitting and Scientific Data Handling 


• Appendix G PyGame 


• Appendix H Plotting with matplotlib 


• GNU Free Document License 


Instructions to Think Like a Computer Scientist: Learning with Python 3 Documentation, Release third 


Release 


Part 1 


The method of the program 


The objective of this book is to instruct you to have a similar outlook as a PC researcher. This perspective consolidates probably the best highlights of arithmetic, designing, and common science. Like mathematicians, PC researchers utilize formal dialects to signify thoughts (explicitly calculations). Like specialists, they plan things, gathering parts into frameworks and assessing tradeoffs among choices. Like researchers, they notice the conduct of complex frameworks, structure theories, and test expectations. 


The absolute most significant expertise for a PC researcher is critical thinking. Critical thinking implies the capacity to detail issues, ponder arrangements, and express an answer obviously and precisely. Things being what they are, the way toward figuring out how to program is a superb chance to rehearse critical thinking abilities. That is the reason this part is called, The method of the program. 


On one level, you will figure out how to program, a valuable expertise without help from anyone else. On another level, you will utilize programming as an unfortunate chore. As we come, that end will become more clear. 


1.1 The Python programming language 


The programming language you will learn is Python. Python is an illustration of an undeniable level language; other significant level dialects you may have known about are C++, PHP, Pascal, C#, and Java. 


As you would surmise from the name undeniable level language, there are additionally low-level dialects, now and again alluded to as machine dialects or low level computing constructs. Freely talking, PCs can just execute programs written in low-level dialects. Along these lines, programs written in a significant level language must be converted into something more appropriate before they can run. 


Practically all projects are written in significant level dialects due for their potential benefits. It is a lot simpler to program in an undeniable level language so programs set aside less effort to compose, they are more limited and simpler to peruse, and they are bound to be right. Second, significant level dialects are compact, implying that they can run on various types of PCs with few or no changes. 


The motor that deciphers and runs Python is known as the Python Interpreter: There are two different ways to utilize it: prompt mode and content mode. In quick mode, you type Python articulations into the Python Interpreter window, and the translator promptly shows the outcome: 


Instructions to Think Like a Computer Scientist: Learning with Python 3 Documentation, Release third 


Version 


The >>> is known as the Python brief. The mediator utilizes the brief to show that it is prepared for guidelines. We composed 2 + 2, and the mediator assessed our demeanor, and answered 4, and on the following line it gave another brief, showing that it is prepared for more info. 


Then again, you can compose a program in a record and utilize the translator to execute the substance of the document. Such a record is known as a content. Contents have the benefit that they can be saved to circle, printed, etc. 


Working straightforwardly in the mediator is helpful for testing short pieces of code since you get prompt criticism. Consider it scratch paper used to help you work out issues. Anything longer than a couple of lines ought to be placed into a content. 


At the point when you are composing a content you need something like a word processor. With this we mean a program on your PC that changes text records, not something that additionally does design like a word processor like Microsoft Word or LibreOffice Writer. A couple of instances of word processors are Notepad, Notepad++, vim, emacs and brilliant. 


For Python (and numerous other programming dialects) there are programs that incorporate both a word processor and an approach to in-teract with the mediator. We call these improvement conditions (now and then Integrated Development Environment or IDE). For Python these can incorporate (among numerous others) Spyder, Thonny or IDLE. There are additionally advancement conditions that run in your program. One illustration of this is Jupyter Notebook. 


The decision of improvement climate is very close to home, however in the event that you are following a course dependent on this book the educator will presumably suggest one. That proposal is convenient to follow in the event that you need assistance utilizing the environ-ment. 


The significant thing to recall is that Python itself doesn't mind in what supervisor you compose your code. However long you compose right linguistic structure (with the correct tabs and spaces) Python can run your program. The editorial manager is just there to help you. 


1.2 What is a program? 


A program is a succession of directions that determines how to play out a calculation. The calculation may be something numerical, like settling an arrangement of conditions or discovering the underlying foundations of a polynomial, however it can likewise be a representative calculation, like looking and supplanting text in a report or (surprisingly) accumulating a program. 


The subtleties appear to be unique in various dialects, yet a couple of fundamental directions show up in pretty much every language: 


input Get information from the console, a document, or some other gadget like a sensor. 


yield Display information on the screen or send information to a document or other gadget like an engine. 


math Perform fundamental numerical tasks like expansion and duplication. 


restrictive execution Check for specific conditions and execute the fitting succession of proclamations. 


redundancy Perform some activity over and again, for the most part with some variety. 


In all honesty, it's as simple as that. Each program you've at any point utilized, regardless of how confounded, is comprised of guidelines that look pretty much like these. In this way, we can depict programming as the interaction of 


The most effective method to Think Like a Computer Scientist: Learning with Python 3 Documentation, Release third 


Version 


breaking a huge, complex undertaking into more modest and more modest subtasks until the subtasks are adequately straightforward to be performed with successions of these essential guidelines. 


That might be somewhat unclear, however we will return to this subject later when we talk about calculations. 


1.3 What is troubleshooting? 


Writing computer programs is an intricate cycle, and on the grounds that it is finished by people, it regularly prompts mistakes. Programming blunders are called bugs and the way toward finding them and rectifying them is called troubleshooting. Utilization of the term bug to depict little designing challenges traces all the way back to in any event 1889, when Thomas Edison had a bug with his phonograph. 


Three sorts of blunders can happen in a program: grammar mistakes, runtime blunders, and semantic mistakes. It is valuable to recognize them to find them all the more rapidly. 


1.4 Syntax blunders 


Python can possibly execute a program if the program is linguistically right; in any case, the cycle comes up short and returns a blunder message. Grammar alludes to the design of a program and the guidelines about that structure. For instance, in English, a sentence should start with a capital letter and end with a period. this sentence contains a grammar mistake. So does this one 


For most perusers, a couple of punctuation blunders are not a huge issue, which is the reason we can peruse the verse of E. E. Cummings without issues. Python isn't so sympathetic. On the off chance that there is a solitary linguistic structure mistake anyplace in your program, Python will show a blunder message and quit, and you won't run your program. During the initial not many long stretches of your programming vocation, you will presumably invest a ton of energy finding grammar mistakes. As you acquire insight, however, you will make less blunders and discover them quicker. 


1.5 Runtime mistakes 


The second sort of blunder is a runtime mistake, purported on the grounds that the blunder doesn't show up until you run the program. These mistakes are additionally called special cases since they as a rule demonstrate that something extraordinary (and terrible) has occurred. 


Runtime mistakes are uncommon in the basic projects you will find in the initial not many parts, so it very well may be some time before you experience one. 


1.6 Semantic blunders 


The third kind of blunder is the semantic mistake. On the off chance that there is a semantic blunder in your program, it will run effectively, as in the PC won't create any mistake messages, yet it won't make the best choice. It will do

No comments:

Post a Comment

Cost Accounting, Management Accounting and Financial Accounting

What is the meaning of Cost Accounting?   Cost accounting is the classification, recording and appropriate allocation of expenditure for...