Support Statistics
¥.00 ·
0times
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
(This page has no text content)
Page
2
v Contents in a Glance Preface xiii Chapter 1 Introduction to Computers and Programming 1 Chapter 2 Input, Processing, and Output 31 Chapter 3 Decision Structures and Boolean Logic 119 Chapter 4 Repetition Structures 169 Chapter 5 Functions 219 Chapter 6 Files and Exceptions 303 Chapter 7 Lists and Tuples 361 Chapter 8 More About Strings 431 Chapter 9 Dictionaries and Sets 467 Chapter 10 Classes and Object-Oriented Programming 521 Chapter 11 Inheritance 583 Chapter 12 Recursion 609 Chapter 13 GUI Programming 629 Chapter 14 Database Programming 717 Appendix A Installing Python 799 Appendix B Introduction to IDLE 803 Appendix C The ASCII Character Set 811 Appendix D Predefined Named Colors 813 Appendix E More About the import Statement 819 Appendix F Formatting Numeric Output with the format() Function 823 Appendix G Installing Modules with the pip Utility 829 Appendix H Answers to Checkpoints 831 Index 853 Credits 869 A01_GADD9032_05_SE_FM.indd 5 11/12/19 2:31 PM
Page
3
vii Contents Preface xiii Chapter 1 Introduction to Computers and Programming 1 1.1 Introduction 1 1.2 Hardware and Software 2 1.3 How Computers Store Data 7 1.4 How a Program Works 12 1.5 Using Python 20 Review Questions 24 Chapter 2 Input, Processing, and Output 31 2.1 Designing a Program 31 2.2 Input, Processing, and Output 35 2.3 Displaying Output with the print Function 36 2.4 Comments 39 2.5 Variables 40 2.6 Reading Input from the Keyboard 49 2.7 Performing Calculations 53 2.8 String Concatenation 65 2.9 More About the print Function 67 2.10 Displaying Formatted Output with F-strings 70 2.11 Named Constants 80 2.12 Introduction to Turtle Graphics 81 Review Questions 109 Programming Exercises 114 Chapter 3 Decision Structures and Boolean Logic 119 3.1 The if Statement 119 3.2 The if-else Statement 128 3.3 Comparing Strings 131 3.4 Nested Decision Structures and the if-elif-else Statement 135 3.5 Logical Operators 143 3.6 Boolean Variables 149 3.7 Turtle Graphics: Determining the State of the Turtle 150 Review Questions 158 Programming Exercises 161 A01_GADD9032_05_SE_FM.indd 7 11/12/19 2:31 PM
Page
4
viii Contents Chapter 4 Repetition Structures 169 4.1 Introduction to Repetition Structures 169 4.2 The while Loop: A Condition-Controlled Loop 170 4.3 The for Loop: A Count-Controlled Loop 178 4.4 Calculating a Running Total 189 4.5 Sentinels 192 4.6 Input Validation Loops 195 4.7 Nested Loops 200 4.8 Turtle Graphics: Using Loops to Draw Designs 207 Review Questions 211 Programming Exercises 213 Chapter 5 Functions 219 5.1 Introduction to Functions 219 5.2 Defining and Calling a Void Function 222 5.3 Designing a Program to Use Functions 227 5.4 Local Variables 233 5.5 Passing Arguments to Functions 236 5.6 Global Variables and Global Constants 246 5.7 Introduction to Value-Returning Functions: Generating Random Numbers 250 5.8 Writing Your Own Value-Returning Functions 261 5.9 The math Module 274 5.10 Storing Functions in Modules 277 5.11 Turtle Graphics: Modularizing Code with Functions 283 Review Questions 289 Programming Exercises 294 Chapter 6 Files and Exceptions 303 6.1 Introduction to File Input and Output 303 6.2 Using Loops to Process Files 321 6.3 Processing Records 328 6.4 Exceptions 341 Review Questions 354 Programming Exercises 358 Chapter 7 Lists and Tuples 361 7.1 Sequences 361 7.2 Introduction to Lists 361 7.3 List Slicing 370 7.4 Finding Items in Lists with the in Operator 373 7.5 List Methods and Useful Built-in Functions 375 7.6 Copying Lists 382 7.7 Processing Lists 383 7.8 List Comprehensions 397 7.9 Two-Dimensional Lists 399 7.10 Tuples 404 7.11 Plotting List Data with the matplotlib Package 406 Review Questions 423 Programming Exercises 426 A01_GADD9032_05_SE_FM.indd 8 11/12/19 2:31 PM
Page
5
Contents ix Chapter 8 More About Strings 431 8.1 Basic String Operations 431 8.2 String Slicing 439 8.3 Testing, Searching, and Manipulating Strings 443 Review Questions 459 Programming Exercises 462 Chapter 9 Dictionaries and Sets 467 9.1 Dictionaries 467 9.2 Sets 493 9.3 Serializing Objects 506 Review Questions 512 Programming Exercises 517 Chapter 10 Classes and Object-Oriented Programming 521 10.1 Procedural and Object-Oriented Programming 521 10.2 Classes 525 10.3 Working with Instances 542 10.4 Techniques for Designing Classe 564 Review Questions 575 Programming Exercises 578 Chapter 11 Inheritance 583 11.1 Introduction to Inheritance 583 11.2 Polymorphism 598 Review Questions 604 Programming Exercises 606 Chapter 12 Recursion 609 12.1 Introduction to Recursion 609 12.2 Problem Solving with Recursion 612 12.3 Examples of Recursive Algorithms 616 Review Questions 624 Programming Exercises 626 Chapter 13 GUI Programming 629 13.1 Graphical User Interfaces 629 13.2 Using the tkinter Module 631 13.3 Displaying Text with Label Widgets 635 13.4 Organizing Widgets with Frames 645 13.5 Button Widgets and Info Dialog Boxes 647 13.6 Getting Input with the Entry Widget 651 13.7 Using Labels as Output Fields 654 13.8 Radio Buttons and Check Buttons 661 13.9 Listbox Widgets 668 13.10 Drawing Shapes with the Canvas Widget 687 Review Questions 710 Programming Exercises 713 A01_GADD9032_05_SE_FM.indd 9 11/12/19 2:31 PM
Page
6
x Contents Chapter 14 Database Programming 717 14.1 Database Management Systems 717 14.2 Tables, Rows, and Columns 719 14.3 Opening and Closing a Database Connection with SQLite 723 14.4 Creating and Deleting Tables 726 14.5 Adding Data to a Table 731 14.6 Querying Data With the SQL SELECT Statement 738 14.7 Updating and Deleting Existing Rows 753 14.8 More About Primary Keys 760 14.9 Handling Database Exceptions 763 14.10 CRUD Operations 766 14.11 Relational Data 774 Review Questions 790 Programming Exercises 796 Appendix A Installing Python 799 Appendix B Introduction to IDLE 803 Appendix C The ASCII Character Set 811 Appendix D Predefined Named Colors 813 Appendix E More About the import Statement 819 Appendix F Formatting Numeric Output with the format() Function 823 Appendix G Installing Modules with the pip Utility 829 Appendix H Answers to Checkpoints 831 Index 853 Credits 869 A01_GADD9032_05_SE_FM.indd 10 11/12/19 2:31 PM
Page
7
LOCATION OF VIDEONOTES IN THE TEXT Chapter 1 Using Interactive Mode in IDLE, p. 23 Performing Exercise 2, p. 28 Chapter 2 The print Function, p. 36 Reading Input from the Keyboard, p. 49 Introduction to Turtle Graphics, p. 81 The Sales Prediction Problem, p. 114 Chapter 3 The if Statement, p. 119 The if-else Statement, p. 128 The Areas of Rectangles Problem, p. 161 Chapter 4 The while Loop, p. 170 The for Loop, p. 178 The Bug Collector Problem, p. 213 Chapter 5 Defining and Calling a Function, p. 222 Passing Arguments to a Function, p. 236 Writing a Value-Returning Function, p. 261 The Kilometer Converter Problem, p. 294 The Feet to Inches Problem, p. 296 Chapter 6 Using Loops to Process Files, p. 321 File Display, p. 358 Chapter 7 List Slicing, p. 370 The Lottery Number Generator Problem, p. 426 Chapter 8 The Vowels and Consonants problem, p. 463 Chapter 9 Introduction to Dictionaries, p. 467 Introduction to Sets, p. 493 The Capital Quiz Problem, p. 518 Chapter 10 Classes and Objects, p. 525 The Pet class, p. 578 Chapter 11 The Person and Customer Classes, p. 607 Chapter 12 The Recursive Multiplication Problem, p. 626 Chapter 13 Creating a Simple GUI application, p. 635 Responding to Button Clicks, p. 647 The Name and Address Problem, p. 713 Chapter 14 Opening and Closing a Database Connection, p. 723 Creating a Table, p. 726 Adding Data to a Table, p. 731 The SELECT Statement, p. 739 Updating Rows, p. 753 Getting Started with the Population Database Problem, p. 796 Appendix B Introduction to IDLE, p. 803 A01_GADD9032_05_SE_FM.indd 11 11/12/19 2:31 PM
Page
8
xiii Welcome to Starting Out with Python, Fifth Edition. This book uses the Python language to teach programming concepts and problem-solving skills, without assuming any previous programming experience. With easy-to-understand examples, pseudocode, flowcharts, and other tools, the student learns how to design the logic of programs then implement those programs using Python. This book is ideal for an introductory programming course or a programming logic and design course using Python as the language. As with all the books in the Starting Out With series, the hallmark of this text is its clear, friendly, and easy-to-understand writing. In addition, it is rich in example programs that are concise and practical. The programs in this book include short examples that highlight specific programming topics, as well as more involved examples that focus on problem solv- ing. Each chapter provides one or more case studies that provide step-by-step analysis of a specific problem and shows the student how to solve it. Control Structures First, Then Classes Python is a fully object-oriented programming language, but students do not have to under- stand object-oriented concepts to start programming in Python. This text first introduces the student to the fundamentals of data storage, input and output, control structures, functions, sequences and lists, file I/O, and objects that are created from standard library classes. Then the student learns to write classes, explores the topics of inheritance and polymorphism, and learns to write recursive functions. Finally, the student learns to develop simple event-driven GUI applications. Changes in the Fifth Edition This book’s clear writing style remains the same as in the previous edition. However, many additions and improvements have been made, which are summarized here: ● Database Programming – This edition adds a new chapter on database programming. Chapter 14 introduces the student to SQL and Python database programming with SQLite. ● Comprehension Expressions – This edition introduces and explains list comprehen- sions, dictionary comprehensions, and set comprehensions. Preface A01_GADD9032_05_SE_FM.indd 13 11/12/19 2:31 PM
Page
9
xiv Preface ● Updated String Topics – Several new string topics have been added, including: o Throughout the text, this edition uses f-strings, which were introduced in Python 3.6, to display formatted output. F-strings use a concise and intuitive syntax and are easier to learn than the format function. The previous material on the format function has been moved to Appendix F. o A new discussion of string tokens has been added to Chapter 8. o A new example of reading and parsing CSV files has been added to Chapter 8. o The discussion of string concatenation in Chapter 2 has been expanded to include implicit concatenation of adjacent strings. ● GUI Programming – Several new GUI programming topics have been added to Chapter 13, including: o Adding borders to widgets o Internal and external padding o Listbox widgets and scrollbars ● Turtle Graphics: Two commands for reading user input with dialog boxes have been introduced: o turtle.numinput o turtle.textinput ● Random List Element Selection – The random.choice() function is introduced in Chapter 7 as a way to randomly select list elements. ● New Function Topics – Several new topics have been added to chapter 5, including: o The pass keyword is introduced o Expanded discussion of the value None, and why a function might return None. o This edition adopts the standard practice of conditionally executing the main function. Brief Overview of Each Chapter Chapter 1: Introduction to Computers and Programming This chapter begins by giving a very concrete and easy-to-understand explanation of how computers work, how data is stored and manipulated, and why we write programs in high- level languages. An introduction to Python, interactive mode, script mode, and the IDLE environment are also given. Chapter 2: Input, Processing, and Output This chapter introduces the program development cycle, variables, data types, and simple programs that are written as sequence structures. The student learns to write simple programs that read input from the keyboard, perform mathematical operations, and produce formatted screen output. Pseudocode and flowcharts are also introduced as tools for designing programs. The chapter also includes an optional introduction to the turtle graphics library. Chapter 3: Decision Structures and Boolean Logic In this chapter, the student learns about relational operators and Boolean expressions and is shown how to control the flow of a program with decision structures. The if, if-else, and A01_GADD9032_05_SE_FM.indd 14 17/12/19 5:45 PM
Page
10
Preface xv if-elif-else statements are covered. Nested decision structures and logical operators are discussed as well. The chapter also includes an optional turtle graphics section, with a discus- sion of how to use decision structures to test the state of the turtle. Chapter 4: Repetition Structures This chapter shows the student how to create repetition structures using the while loop and for loop. Counters, accumulators, running totals, and sentinels are discussed, as well as techniques for writing input validation loops. The chapter also includes an optional section on using loops to draw designs with the turtle graphics library. Chapter 5: Functions In this chapter, the student first learns how to write and call void functions. The chapter shows the benefits of using functions to modularize programs and discusses the top-down design approach. Then, the student learns to pass arguments to functions. Common library functions, such as those for generating random numbers, are discussed. After learning how to call library functions and use their return value, the student learns to define and call his or her own functions. Then the student learns how to use modules to organize functions. An optional section includes a discussion of modularizing turtle graphics code with functions. Chapter 6: Files and Exceptions This chapter introduces sequential file input and output. The student learns to read and write large sets of data and store data as fields and records. The chapter concludes by discussing exceptions and shows the student how to write exception-handling code. Chapter 7: Lists and Tuples This chapter introduces the student to the concept of a sequence in Python and explores the use of two common Python sequences: lists and tuples. The student learns to use lists for arraylike operations, such as storing objects in a list, iterating over a list, searching for items in a list, and calculating the sum and average of items in a list. The chapter discusses list comprehension expressions, slicing, and many of the list methods. One- and two- dimensional lists are covered. The chapter also includes a discussion of the matplotlib package, and how to use it to plot charts and graphs from lists. Chapter 8: More About Strings In this chapter, the student learns to process strings at a detailed level. String slicing and algorithms that step through the individual characters in a string are discussed, and several built-in functions and string methods for character and text processing are introduced. This chapter also includes examples of string tokenizing and parsing CSV files. Chapter 9: Dictionaries and Sets This chapter introduces the dictionary and set data structures. The student learns to store data as key-value pairs in dictionaries, search for values, change existing values, add new A01_GADD9032_05_SE_FM.indd 15 11/12/19 2:31 PM
Page
11
xvi Preface key-value pairs, delete key-value pairs, and write dictionary comprehensions. The student learns to store values as unique elements in sets and perform common set operations such as union, intersection, difference, and symmetric difference. Set comprehensions are also introduced. The chapter concludes with a discussion of object serialization and introduces the student to the Python pickle module. Chapter 10: Classes and Object-Oriented Programming This chapter compares procedural and object-oriented programming practices. It covers the fundamental concepts of classes and objects. Attributes, methods, encapsulation and data hiding, _ _init_ _ functions (which are similar to constructors), accessors, and mutators are discussed. The student learns how to model classes with UML and how to find the classes in a particular problem. Chapter 11: Inheritance The study of classes continues in this chapter with the subjects of inheritance and polymor- phism. The topics covered include superclasses, subclasses, how _ _init_ _ functions work in inheritance, method overriding, and polymorphism. Chapter 12: Recursion This chapter discusses recursion and its use in problem solving. A visual trace of recursive calls is provided, and recursive applications are discussed. Recursive algorithms for many tasks are presented, such as finding factorials, finding a greatest common denominator (GCD), and sum- ming a range of values in a list, and the classic Towers of Hanoi example are presented. Chapter 13: GUI Programming This chapter discusses the basic aspects of designing a GUI application using the tkinter module in Python. Fundamental widgets, such as labels, buttons, entry fields, radio buttons, check buttons, list boxes, and dialog boxes, are covered. The student also learns how events work in a GUI application and how to write callback functions to handle events. The Chapter includes a discussion of the Canvas widget, and how to use it to draw lines, rectangles, ovals, arcs, polygons, and text. Chapter 14: Database Programming This chapter introduces the student to database programming. The chapter first introduces the basic concepts of databases, such as tables, rows, and primary keys. Then the student learns to use SQLite to connect to a database in Python. SQL is introduced and the student learns to execute queries and statements that search for rows, add new rows, update existing rows, and delete rows. CRUD applications are demonstrated, and the chapter concludes with a discussion of relational data. Appendix A: Installing Python This appendix explains how to download and install the latest Python distribution. A01_GADD9032_05_SE_FM.indd 16 11/12/19 2:31 PM
Page
12
Preface xvii Appendix B: Introduction to IDLE This appendix gives an overview of the IDLE integrated development environment that comes with Python. Appendix C: The ASCII Character Set As a reference, this appendix lists the ASCII character set. Appendix D: Predefined Named Colors This appendix lists the predefined color names that can be used with the turtle graphics library, matplotlib and tkinter. Appendix E: More About the import Statement This appendix discusses various ways to use the import statement. For example, you can use the import statement to import a module, a class, a function, or to assign an alias to a module. Appendix F: Formatting Numeric Output with the format() Function This appendix discusses the format() function and shows how to use its format specifiers to control the way that numeric values are displayed. Appendix G: Installing Modules with the pip Utility This appendix discusses how to use the pip utility to install third-party modules from the Python Package Index, or PyPI. Appendix H: Answers to Checkpoints This appendix gives the answers to the Checkpoint questions that appear throughout the text. Organization of the Text The text teaches programming in a step-by-step manner. Each chapter covers a major set of topics and builds knowledge as students progress through the book. Although the chapters can be easily taught in their existing sequence, you do have some flexibility in the order that you wish to cover them. Figure P-1 shows chapter dependencies. Each box represents a chapter or a group of chapters. An arrow points from a chapter to the chapter that must be covered before it. A01_GADD9032_05_SE_FM.indd 17 11/12/19 2:31 PM
Page
13
xviii Preface Features of the Text Concept Each major section of the text starts with a concept statement. Statements This statement concisely summarizes the main point of the section. Example Programs Each chapter has an abundant number of complete and partial example programs, each designed to highlight the current topic. In the Spotlight Each chapter has one or more In the Spotlight case studies that Case Studies provide detailed, step-by-step analysis of problems and show the student how to solve them. VideoNotes Online videos developed specifically for this book are avail- able for viewing at www.pearsonhighered.com/cs-resources. Icons appear throughout the text alerting the student to videos about specific topics. Chapters 1-5 (Cover in Order) Chapter 7 Lists and Tuples Chapter 6 Files and Exceptions Chapter 12 Recursion Chapter 11 Inheritance Chapter 13 GUI Programming Chapter 10 Classes and Object- Oriented Programming Chapter 8 More About Strings Chapter 9 Dictionaries and Sets Chapter 14 Database Programming Chapter 14 includes one example that uses a GUI interface. Figure P-1 Chapter dependencies A01_GADD9032_05_SE_FM.indd 18 11/12/19 2:31 PM
Page
14
Preface xix Notes Notes appear at several places throughout the text. They are short explanations of interesting or often misunderstood points relevant to the topic at hand. Tips Tips advise the student on the best techniques for approaching different programming problems. Warnings Warnings caution students about programming techniques or practices that can lead to malfunctioning programs or lost data. Checkpoints Checkpoints are questions placed at intervals throughout each chapter. They are designed to query the student’s knowledge quickly after learning a new topic. Please note that the Checkpoint exercises in this textbook may differ from the Checkpoint questions embedded in the digital product Revel Starting Out with Python. Review Questions Each chapter presents a thorough and diverse set of review questions and exercises. They include Multiple Choice, True/ False, Algorithm Workbench, and Short Answer. Programming Each chapter offers a pool of programming exercises designed Exercises to solidify the student’s knowledge of the topics currently being studied. Please note that the end-of-chapter Programming Exercises in this textbook may differ from the end-of-chapter Programming Exercises embedded in the digital product Revel Starting Out with Python. Supplements Student Online Resources Many student resources are available for this book from the publisher. The following items are available at www.pearsonhighered.com/cs-resources ● The source code for each example program in the book ● Access to the book’s companion VideoNotes Instructor Resources The following supplements are available to qualified instructors only: ● Answers to all of the Review Questions ● Solutions for the exercises ● PowerPoint presentation slides for each chapter ● Test bank Visit the Pearson Education Instructor Resource Center (www.pearsonhighered.com/irc) or contact your local Pearson Education campus representative for information on how to access them. Acknowledgments I would like to thank the following faculty reviewers for their insight, expertise, and thought- ful recommendations: Paul Amer University of Delaware James Atlas University of Delaware James Carrier Guilford Technical Community College John Cavazos University of Delaware A01_GADD9032_05_SE_FM.indd 19 17/12/19 11:39 AM
Page
15
xx Preface I would like to thank the faculty, staff, and administration at Haywood Community College for the opportunity to build a career teaching the subjects that I love. I would also like to thank my family and friends for their support in all of my projects. It is a great honor to be published by Pearson, and I am extremely fortunate to have Tracy Johnson as my Editor and Content Manager. She and her colleagues Holly Stark, Erin Sullivan, Alicia Wilson, Scott Disanno, Carole Snyder, Bob Engelhardt, and Aishwarya Panday have worked tirelessly to produce and promote this book. Thanks to you all! About the Author Tony Gaddis is the principal author of the Starting Out With series of textbooks. Tony has nearly two decades of experience teaching computer science courses at Haywood Com- munity College. He is a highly acclaimed instructor who was previously selected as the North Carolina Community College “Teacher of the Year” and has received the Teaching Excellence award from the National Institute for Staff and Organizational Development. The Starting Out with series includes introductory books covering C++, Java™, Microsoft® Visual Basic®, Microsoft® C#®, Python®, Programming Logic and Design, Alice, and App Inventor, all published by Pearson. More information about all these books can be found at www.pearsonhighered.com/gaddisbooks. Desmond K. H. Chun Chabot Community College Sonya Dennis Morehouse College Barbara Goldner North Seattle Community College Paul Gruhn Manchester Community College Bob Husson Craven Community College Diane Innes Sandhills Community College Daniel Jinguji North Seattle Community College John Kinuthia Nazareth College of Rochester Frank Liu Sam Houston State University Gary Marrer Glendale Community College Keith Mehl Chabot College Shyamal Mitra University of Texas at Austin Vince Offenback North Seattle Community College Smiljana Petrovic Iona College Raymond Pettit Abilene Christian University Janet Renwick University of Arkansas–Fort Smith Haris Ribic SUNY at Binghamton Ken Robol Beaufort Community College Eric Shaffer University of Illinois at Urbana- Champaign Tom Stokke University of North Dakota Anita Sutton Germanna Community College Ann Ford Tyson Florida State University Karen Ughetta Virginia Western Community College Christopher Urban SUNY Institute of Technology Nanette Veilleux Simmons College Brent Wilson George Fox University Linda F. Wilson Texas Lutheran University A01_GADD9032_05_SE_FM.indd 20 17/12/19 5:46 PM
Page
16
A01_GADD9032_05_SE_FM.indd 21 11/12/19 2:31 PM
Page
17
1 1.1 Introduction Think about some of the different ways that people use computers. In school, students use computers for tasks such as writing papers, searching for articles, sending email, and participating in online classes. At work, people use computers to analyze data, make pre- sentations, conduct business transactions, communicate with customers and coworkers, control machines in manufacturing facilities, and do many other things. At home, people use computers for tasks such as paying bills, shopping online, communicating with friends and family, and playing games. And don’t forget that cell phones, tablets, smart phones, car navigation systems, and many other devices are computers too. The uses of computers are almost limitless in our everyday lives. Computers can perform such a wide variety of tasks because they can be programmed. This means that computers are not designed to do just one job, but to do any job that their pro- grams tell them to do. A program is a set of instructions that a computer follows to perform a task. For example, Figure 1-1 shows screens using Microsoft Word and PowerPoint, two commonly used programs. Programs are commonly referred to as software. Software is essential to a computer because it controls everything the computer does. All of the software that we use to make our com- puters useful is created by individuals working as programmers or software developers. A programmer, or software developer, is a person with the training and skills necessary to design, create, and test computer programs. Computer programming is an exciting and rewarding career. Today, you will find programmers’ work used in business, medicine, gov- ernment, law enforcement, agriculture, academics, entertainment, and many other fields. This book introduces you to the fundamental concepts of computer programming using the Python language. The Python language is a good choice for beginners because it is easy to learn Introduction to Computers and Programming1 TOPICS 1.1 Introduction 1.2 Hardware and Software 1.3 How Computers Store Data 1.4 How a Program Works 1.5 Using Python C H A P T E R M01_GADD9032_05_SE_C01.indd 1 11/12/19 1:50 PM
Page
18
2 Chapter 1 Introduction to Computers and Programming and programs can be written quickly using it. Python is also a powerful language, popular with professional software developers. In fact, it has been reported that Python is used by Google, NASA, YouTube, various game companies, the New York Stock Exchange, and many others. Before we begin exploring the concepts of programming, you need to understand a few basic things about computers and how they work. This chapter will build a solid founda- tion of knowledge that you will continually rely on as you study computer science. First, we will discuss the physical components of which computers are commonly made. Next, we will look at how computers store data and execute programs. Finally, you will get a quick introduction to the software that you will use to write Python programs. Figure 1-1 A word processing program and a presentation program 1.2 Hardware and Software CONCEPT: The physical devices of which a computer is made are referred to as the computer’s hardware. The programs that run on a computer are referred to as software. Hardware The term hardware refers to all of the physical devices, or components, of which a computer is made. A computer is not one single device, but a system of devices that all work toge- ther. Like the different instruments in a symphony orchestra, each device in a computer plays its own part. If you have ever shopped for a computer, you’ve probably seen sales literature listing compo- nents such as microprocessors, memory, disk drives, video displays, graphics cards, and so on. Unless you already know a lot about computers, or at least have a friend that does, under- standing what these different components do might be challenging. As shown in Figure 1-2, a typical computer system consists of the following major components: • The central processing unit (CPU) • Main memory M01_GADD9032_05_SE_C01.indd 2 11/12/19 1:50 PM
Page
19
1.2 Hardware and Software 3 • Secondary storage devices • Input devices • Output devices Let’s take a closer look at each of these components. The CPU When a computer is performing the tasks that a program tells it to do, we say that the computer is running or executing the program. The central processing unit, or CPU, is the part of a computer that actually runs programs. The CPU is the most important component in a computer because without it, the computer could not run software. In the earliest computers, CPUs were huge devices made of electrical and mechanical com- ponents such as vacuum tubes and switches. Figure 1-3 shows such a device. The two women in the photo are working with the historic ENIAC computer. The ENIAC, which is considered by many to be the world’s first programmable electronic computer, was built in 1945 to calculate artillery ballistic tables for the U.S. Army. This machine, which was primarily one big CPU, was 8 feet tall, 100 feet long, and weighed 30 tons. Today, CPUs are small chips known as microprocessors. Figure 1-4 shows a photo of a lab technician holding a modern microprocessor. In addition to being much smaller than the old electromechanical CPUs in early computers, microprocessors are also much more powerful. Input Devices Output Devices Secondary Storage Devices Central Processing Unit Main Memory (RAM) Iko/Shutterstock A q ui la / Sh ut te rs to ck Pe te r G ue ss / Sh ut te rs to ck StockPhotosArt/Shutterstock Jocic/Shutterstock A rt g al le ry / Sh ut te rs to ck Elkostas/Shutterstock Tkemot/Shutterstock Andre Nitsievsky/Shutterstock. Chiyacat/ ShutterstockFe ng Y u/ Sh ut te rs to ck N ik ita R og ul / Sh ut te rs to ck Kastianz/Shutterstock Figure 1-2 Typical components of a computer system M01_GADD9032_05_SE_C01.indd 3 11/12/19 1:50 PM
Page
20
4 Chapter 1 Introduction to Computers and Programming Figure 1-3 The ENIAC computer courtesy of U.S. Army Historic Computer Images Figure 1-4 A lab technician holds a modern microprocessor Creativa Images/Shutterstock M01_GADD9032_05_SE_C01.indd 4 11/12/19 1:50 PM
Comments 0
Loading comments...
Reply to Comment
Edit Comment