Starting Out with Python 4th Global Edition pdf pdf

Gratis

0
0
748
3 months ago
Preview
Full text

GLOBAL EDITION

  Pearson Education LimitedKAO Two KAO ParkHarlow CM17 9NAUnited Kingdom and Associated Companies throughout the worldVisit us on the World Wide Web at: www.pearsonglobaleditions.com© Pearson Education Limited 2019 The rights of Tony Gaddis to be identified as the author of this work has been asserted by him in accor-dance with the Copyright, Designs and Patents Act 1988. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without eitherthe prior written permission of the publisher or a license permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.

FOURTH EDITION

  Pearson Education LimitedKAO Two KAO ParkHarlow CM17 9NAUnited Kingdom and Associated Companies throughout the worldVisit us on the World Wide Web at: www.pearsonglobaleditions.com© Pearson Education Limited 2019 The rights of Tony Gaddis to be identified as the author of this work has been asserted by him in accor-dance with the Copyright, Designs and Patents Act 1988. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without eitherthe prior written permission of the publisher or a license permitting restricted copying in the United Kingdom issued by the Copyright Licensing Agency Ltd, Saffron House, 6–10 Kirby Street, London EC1N 8TS.

ISBN 10: 1-292-22575-0ISBN 13: 978-1-292-22575-3

® Typeset by iEnergizer Aptara , Ltd. Chapter 1 Introduction to Computers and Programming Chapter 11 Inheritance573 725 Index 701 appendix F Installing Modules with the pip Utility 705appendix G Answers to Checkpoints 707 More About the import Statement Chapter 13 GUI Programming619 appendix a Installing Python681 appendix b Introduction to IDLE 685appendix C The ASCII Character Set 693 appendix d Predefined Named Colors 695appendix E Chapter 12 Recursion599 Chapter 9 Dictionaries and Sets 461 Chapter 10 Classes and Object-Oriented Programming511 23 Chapter 2 Chapter 8 More About Strings429 Chapter 7 Lists and Tuples365 Chapter 6 Files and Exceptions309 Chapter 5 Functions231 Chapter 4 Repetition Structures181 53 Chapter 3 Decision Structures and Boolean Logic 131 Input, Processing, and Output Credits 743 This page intentionally left blank Chapter 1 Introduction to Computers and Programming 23 1.1 Introduction 23 1.2 Hardware and Software 24 1.3 How Computers Store Data 29 1.4 How a Program Works 34 1.5 Using Python 42 Review Questions 46 Chapter 2 Input, Processing, and Output 53 2.1 Designing a Program 53 2.2 Input, Processing, and Output 57 print 2.3 Displaying Output with the Function 58 2.4 Comments 61 2.5 Variables 62 2.6 Reading Input from the Keyboard 71 2.7 Performing Calculations 75 2.8 More About Data Output 87 2.9 Named Constants 95 2.10 Introduction to Turtle Graphics 96 Review Questions122 Programming Exercises 126 Chapter 3 Decision Structures and Boolean Logic 131 3.1 The if Statement131 if-else 3.2 The Statement140 3.3 Comparing Strings143 3.4 Nested Decision Structures and the if-elif-else Statement 147 3.5 Logical Operators155 3.6 Boolean Variables161 3.7 Turtle Graphics: Determining the State of the Turtle 162 Review Questions 170 Programming Exercises 173 8Contents 7.3 List Slicing373 Programming Exercises 302 Chapter 6 Files and Exceptions 309 6.1 Introduction to File Input and Output 309 6.2 Using Loops to Process Files 326 6.3 Processing Records333 6.4 Exceptions346 Review Questions 359 Programming Exercises 362 Chapter 7 Lists and Tuples365 7.1 Sequences365 7.2 Introduction to Lists365 7.4 Finding Items in Lists with the in Operator 376 Review Questions 7.5 List Methods and Useful Built-in Functions 377 7.6 Copying Lists384 7.7 Processing Lists386 7.8 Two-Dimensional Lists 398 7.9 Tuples402 7.10 Plotting List Data with the matplotlib Package 405 Review Questions 421 297 5.11 Turtle Graphics: Modularizing Code with Functions 290 Chapter 4 Repetition Structures 181 Review Questions 223 Programming Exercises 225 4.1 Introduction to Repetition Structures 181 4.2 The while Loop: A Condition-Controlled Loop 182 4.3 The for Loop: A Count-Controlled Loop 190 4.4 Calculating a Running Total 201 4.5 Sentinels204 4.6 Input Validation Loops 207 4.7 Nested Loops212 4.8 Turtle Graphics: Using Loops to Draw Designs 219 Chapter 5 Functions231 5.10 Storing Functions in Modules 286 5.1 Introduction to Functions 231 5.2 Defining and Calling a Void Function 234 5.3 Designing a Program to Use Functions 239 5.4 Local Variables245 5.5 Passing Arguments to Functions 247 5.6 Global Variables and Global Constants 257 5.7 Introduction to Value-Returning Functions: GeneratingRandom Numbers 261 5.8 Writing Your Own Value-Returning Functions 272 5.9 The math Module283 Programming Exercises 424 9Contents Chapter 8429 More About Strings 8.1 Basic String Operations 429 8.2 String Slicing437 8.3 Testing, Searching, and Manipulating Strings 441 Review Questions 453 Programming Exercises 456 Chapter 9461 Dictionaries and Sets 9.1 Dictionaries461 9.2 Sets484 9.3 Serializing Objects496 Review Questions 502 Programming Exercises 507 Chapter 10511 Classes and Object-Oriented Programming 10.1 Procedural and Object-Oriented Programming 511 10.2 Classes515 10.3 Working with Instances 532 10.4 Techniques for Designing Classes 554 Review Questions 565 Programming Exercises 568 Chapter 11573 Inheritance 11.1 Introduction to Inheritance 573 11.2 Polymorphism588 Review Questions 594 Programming Exercises 596 Chapter 12599 Recursion 12.1 Introduction to Recursion 599 12.2 Problem Solving with Recursion 602 12.3 Examples of Recursive Algorithms 606 Review Questions 614 Programming Exercises 616 Chapter 13619 GUI Programming 13.1 Graphical User Interfaces 619 13.2 Using the tkinter Module 621 Label 13.3 Display Text with Widgets 624 13.4 Organizing Widgets with Frame s 627 Button 13.5 Widgets and Info Dialog Boxes 630 13.6 Getting Input with the Entry Widget 633 13.7 Using Labels as Output Fields 636 13.8 Radio Buttons and Check Buttons 644 Canvas 13.9 Drawing Shapes with the Widget 651 Review Questions 673 Programming Exercises 676 10Contents appendix a Installing Python681 appendix b Introduction to IDLE 685appendix C The ASCII Character Set 693 appendix d Predefined Named Colors 695appendix E More About the import Statement 701 appendix F Installing Modules with the pip Utility 705appendix G Answers to Checkpoints 707 Index 725 Credits 743

LOCATION OF VIDEONOTES IN THE TEXT

  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 itemsin a list, and calculating the sum and average of items in a list.

Chapter 10: Classes and Object-Oriented Programming This chapter compares procedural and object-oriented programming practices. It covers the

  The operating system controls the internal operations of the computer’s hard- ware, manages all of the devices connected to the computer, allows data to be saved toand retrieved from storage devices, and allows other programs to run on the computer. For example, the pattern on the left in Figure 1-7 showshow the number 77 would be stored in a byte, and the pattern on the right shows how the letter A would be stored in a byte.

65 A

  Because people find it very difficult to write entire programs in machine language, other programming languages have been 1.4 how a Program Works Earlier, we stated that the CPU is the most important component in a computer because it is the part of the computer that runs programs. Sometimes the CPU is called the “computer’sbrain” and is described as being “smart.” Although these are common metaphors, you should understand that the CPU is not a brain, and it is not smart.

1 The example shown is an actual instruction for an Intel microprocessor. It tells the microprocessor

  Here is an example of how you type this statement at the interpreter’sprompt: Enter>>> print('Python programming is fun!') After typing the statement, you press the Enter key, and the Python interpreter executes the statement, as shown here: Enter>>> print('Python programming is fun!') Python programming is fun!>>> After the message is displayed, the >>> prompt appears again, indicating the interpreter is waiting for you to enter another statement. We use the line numbers in our discussion to refer to parts of the program.) Program 2-1 (output.py)1 print('Kate Austen') 2 print('123 Full Circle Drive')3 print('Asheville, NC 28899') Program OutputKate Austen 123 Full Circle DriveAsheville, NC 28899 It is important to understand that the statements in this program execute in the order that they appear, from the top of the program to the bottom.

99 Enter

  4 >>> x = 'Take me to your leader'Enter 5 >>> print(x) 6 Take me to your leader.7 >>> The statement in line 1 creates a variable named x and assigns it the int value 99. After this statementexecutes, the x variable no longer refers to an int , but to the string 'Take me to your leader' .

99 Take me to your leader

  (You can think of the newline character as a special command thatcauses the computer to start a new line of output.)If you do not want the print function to start a new line of output when it finishes dis- playing its output, you can pass the special argument end = ' ' to the function, as shownin the following code: print('One', end=' ') print('Two', end=' ')print('Three') Notice in the first two statements, the argument end = ' ' is passed to the print function. She has determined that after measuring the length of afuture row, she can use the following formula to calculate the number of vines that will fit in the row, along with the trellis end-post assemblies that will need to be constructed ateach end of the row: R 2 2E V 5 S The terms in the formula are: V is the number of grapevines that will fit in the row.

7 HIGH_SCORE = 95

  If it is true, the block of indented state- ments following the if clause is executed, then control of the program jumps to the state-ment that follows the if-else statement. (For example, the string would be stored in memory as the codes 97, 98, 99, 49, 50, and 51.) if 'a' < 'b': 3.3 Comparing Strings This code determines whether the ASCII code for the character 'a' is less than the ASCII code for the character 'b' .

3.4 Nested Decision Structures and the

  In Section 3.1, we mentioned that a control structure determines the order in which a set of statements execute. For example, Figure 3-10 shows a flowchart that combines a decision structure with two sequence structures.

Dokumen baru

Aktifitas terbaru

Download (748 Halaman)
Gratis

Tags

Problem Solving With C 10Th Global Edition Pdf Pdf Software Architecture With Python Pdf Pdf Cisco Press Internetworking Technologies Handbook 4Th Edition Pdf Pdf The Object Oriented Thought Process 4Th Edition Pdf Pdf Introduction To Computing Using Python 2Nd Edition Pdf Pdf C How To Program 10Th Global Edition Pdf Pdf
Show more