![Computer Science Principles with Python](https://data.docslib.org/img/3a60ab92a6e30910dab9bd827208bcff-1.webp)
Rowan University Rowan Digital Works Open Educational Resources University Libraries 8-2-2021 Computer Science Principles with Python Seth D. Bergmann Rowan University Follow this and additional works at: https://rdw.rowan.edu/oer Part of the Computer Sciences Commons DOI: 10.31986/issn.2689-0690_rdw.oer.1024 Let us know how access to this document benefits ouy - share your thoughts on our feedback form. Recommended Citation Bergmann, Seth D., "Computer Science Principles with Python" (2021). Open Educational Resources. 25. https://rdw.rowan.edu/oer/25 This Book is brought to you for free and open access by the University Libraries at Rowan Digital Works. It has been accepted for inclusion in Open Educational Resources by an authorized administrator of Rowan Digital Works. Computer Science Principles Python edition Seth D. Bergmann September 15, 2021 2 Preface This book is intended to be used for a first course in computer science. It in- cludes some programming, but the emphasis is on the principles which form the foundation for hardware and software. No prior experience with programming should be necessary in order to use this book. This book is intended to be used for the College Board’s Advanced Placement course known as AP Computer Science Principles (CSP). This course is not to be confused with a more traditional course known as AP Computer Science A, which places a strong emphasis on programming, currently using Java. The author(s) of this book have included all the topics that are in CSP.1 We feel that there are some related topics which may be of interest to those who are new to computer science; in many cases we have included these extra topics, but they are denoted by a symbol to indicate they are not part of the official CSP course, and students taking⊗ the AP CSP exam will not be responsible for these topics. Since the AP exams are given in early May, and most school years end in mid-June, many may wish to visit these extra topics after taking the AP exam. The author(s) believe that a breadth-first approach is the best way to intro- duce the concepts of Computer Science to students. Rather than isolate topics in courses (bits and bytes in a computer organization course; formal grammars and languages in a theory course; lists, sets, and maps in a data structurs course; etc) we believe that topics should be introduced in a brief and simple manner at the starting level. Elaboration on these topics should occur in subsequent courses. This breadth-first approach allows the student to build on existing knowledge and retain a greater proportion of the material. Our colleagues in the physical sciences have done this for over a century: Physics I, Physics II, Physics III; Chemistry I, Chemistry II, Chemistry III. Some examples of this breadth-first approach to Computer Science: • We teach the rudiments of binary numbers. Is this necessary to learn to program the solution to a simple problem? Probably not, but it will become necessary at some later time, when studying hardware, or the limitations of software. 1We are using the Computer Science Principles Framework dated 2020, by the The College Board. i ii PREFACE • Every introductory programming book teaches the concept of an arith- metic expression. We give a formal definition, and show the structure of an expression by placing boxes around sub-expressions. The student thinks we are teaching how to write a correct expression; we are actually teaching recursion, formal grammars, and derivation trees. The student thinks we are teaching programming, but we are actually teach- ing Computer Science. Knowledge is not separated into compartments, and our curriculum should not attempt to do so. Though the Computer Science Principles course is not intended to be a computer programming course, it does have a brief introductory programming component. For that purpose there are editions of this book which use either Java or Python (an edition using C++ is planned). Check the title page or table of contents to determine which edition you are viewing. This book is an open source book. That means that not only is the pdf version available (to potential students and teachers) for free download, but that the original (LaTeX) source files are also available (to potential authors and contributors). Based on the model of open source software, open source for textbooks is a relatively new paradigm in which many authors and contributors can cooperate to produce a high quality product, for no compensation. For details on the rationale of this new paradigm, and citations for other open source textbooks, see the journal Publishing Research Quarterly, Vol. 30, No. 1, March 2014. The source materials and pdf files of this book are licensed with the Creative Commons NonCommercial and Attributioon licenses (NC+BY), which means that they may be freely used, copied, or modified, but not for financial gain, and that the author(s) must be cited. This book is available in pdf at rdw.rowan.edu /oer. The source files are available at cs.rowan.edu/ bergmann/books. The primary author may be reached at [email protected]∼ Secondary Authors Contributors Kim Poolos, Rowan University Minor Contributors Poonam Gupta, Brunswick Academy Technical Consultant Joshua Grochowski, Rowan University Contents Preface i 1 Creativity 1 1.1 ComputationalArtifacts . 1 1.1.1 Exercises ........................... 2 1.2 Creative Expression and Problem Solutions . 3 1.2.1 Tool: ComputerwithOfficePackage . 3 1.2.2 Tool: Computer with Programming Environment . 3 1.2.3 OtherTools.......................... 6 1.2.4 Exercises ........................... 8 1.3 ExtendingtheHumanExperience. 9 1.3.1 Creativity........................... 9 1.3.2 Problem solution . 10 1.3.3 Exercises ........................... 14 2 Abstraction 15 2.1 Binarysequencesanddigitaldevices . 15 2.1.1 Exercises ........................... 16 2.2 Representingintegers. 17 2.2.1 Numbersystems ....................... 17 2.2.2 Representing positive integers . 20 2.2.3 Representing negative integers . 22 2.2.4 Exercises ........................... 24 2.3 Representingnon-integernumbers . 26 2.3.1 Exercises ........................... 27 2.4 Representing integers with unlimited precision⊗ .......... 28 2.4.1 Exercises ........................... 28 2.5 Representingplaintext ....................... 29 2.5.1 Exercises ........................... 30 2.6 Representinggraphicimages. 30 2.6.1 Black and white images . 30 2.6.2 Colorimages ......................... 32 2.6.3 Exercises ........................... 32 2.7 Representingsoundandvideo. 33 iii iv CONTENTS 2.7.1 Representingsound .. .. .. .. .. .. .. .. .. 33 2.7.2 Representingvideo. .. .. .. .. .. .. .. .. .. 34 2.7.3 Exercises ........................... 35 2.8 Lookingintomemory......................... 36 2.8.1 Exercises ........................... 37 2.9 Abstractionsinprograms . 38 2.9.1 Programabstractions . 38 2.9.2 Levels of abstraction in software . 41 2.9.3 Exercises ........................... 44 2.10 Levels of abstraction in hardware⊗ ................. 46 2.10.1 Exercises ........................... 57 2.11 Levels of Abstraction in Models and Simulations . 57 2.11.1 Weather............................ 58 2.11.2 Evolution ........................... 59 2.11.3 Warfare ............................ 61 2.11.4 Biological Populations and Environments . 62 2.11.5 Climate ............................ 64 2.11.6 Training............................ 65 2.11.7 Exercises ........................... 66 3 Data and Information 69 3.1 InformationProcessing. 69 3.1.1 Processinig Information to Gain Insight or Knowledge . 69 3.1.2 Collaboration . 70 3.1.3 Explanation with Visualization or Notation . 71 3.1.4 Exercises ........................... 72 3.2 Information: ExplorationandDiscovery . 73 3.2.1 Extracting Information from Large Datasets. 73 3.2.2 Data analytics⊗ ....................... 76 3.2.3 Machine learning⊗ ...................... 76 3.2.4 Exercises ........................... 76 3.3 DigitalData.............................. 77 3.3.1 TimeandSpaceEfficiency. 77 3.3.2 SecurityandPrivacy.. .. .. .. .. .. .. .. .. 77 3.3.3 AccesstoData ........................ 78 3.3.4 Exercises ........................... 79 4Algorithms 80 4.1 Algorithm design and implementation . 80 4.1.1 Variables, assignments, and the sequence control structure 81 4.1.2 Boolean expressions and selections . 82 4.1.3 Iteration............................ 87 4.1.4 Lists.............................. 89 4.1.5 Nestedcontrolstructures . 93 4.1.6 AbstractionofAlgorithms: Procedures. 94 4.1.7 LanguagesforAlgorithms . 106 CONTENTS v 4.1.8 Robot algorithmic language . 108 4.1.9 Exercises ........................... 109 4.2 Limitations of algorithms . 112 4.2.1 Algorithmperformance . 112 4.2.2 Solvable problems . 118 4.2.3 Undecidable problems . 119 4.2.4 Evaluation of algorithms . 119 4.2.5 Exercises ........................... 121 5 Programming (with Python) 123 5.1 Programdevelopment . 123 5.1.1 Whyprogram? ........................ 123 5.1.2 Problem solution . 124 5.1.3 Collaboration . 126 5.1.4 Exercises ........................... 126 5.2 Algorithm implementation . 127 5.2.1 Pythonversions ....................... 127 5.2.2 Sequence ........................... 127 5.2.3 Selection ...........................129 5.2.4 Iteration............................ 130 5.2.5 Print..............................131 5.2.6 Exercises ........................... 132 5.3 Programabstractions . 133 5.3.1 Fruitful functions in Python . 134 5.3.2 Reducing complexity with abstractions . 135 5.3.3
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages263 Page
-
File Size-