Starting Out With Python, 5th Edition PDF by Tony Gaddis

By

Starting Out With Python, Fifth Edition

By Tony Gaddis

Starting Out With Python, 5th Edition

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

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

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

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

Preface

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 solving. 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 understand 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:

1. Database Programming – This edition adds a new chapter on database programming. Chapter 14 introduces the student to SQL and Python database programming with SQLite.

2. Comprehension Expressions – This edition introduces and explains list comprehensions, dictionary comprehensions, and set comprehensions.

3. Updated String Topics – Several new string topics have been added, including:

  • 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.
  • A new discussion of string tokens has been added to Chapter 8.
  • A new example of reading and parsing CSV files has been added to Chapter 8.
  • The discussion of string concatenation in Chapter 2 has been expanded to include implicit concatenation of adjacent strings.

4. GUI Programming – Several new GUI programming topics have been added to Chapter 13, including:

  • Adding borders to widgets
  • Internal and external padding
  • Listbox widgets and scrollbars

5. Turtle Graphics: Two commands for reading user input with dialog boxes have been introduced:

  • turtle.numinput
  • turtle.textinput

6. Random List Element Selection – The random.choice() function is introduced in Chapter 7 as a way to randomly select list elements.

7. New Function Topics – Several new topics have been added to chapter 5, including:

  • The pass keyword is introduced
  • Expanded discussion of the value None, and why a function might return None.
  • This edition adopts the standard practice of conditionally executing the main function.

This book is US$10. Order for this book:
(Request for free sample pages click on "Order Now" button)

Book Order
Or, Send email: [email protected]

Share this Book!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.