Description

Book Synopsis
Ben Forta is, first and foremost, an educator who has been teaching in some capacity since he was a teenager (many centuries ago). He is Adobe's Senior Director of Education Initiatives, and has more than three decades of experience in the technology sector in product development, support, training, and product marketing. Ben is the award-winning author of more than 40 books, some of which have been translated into 16 languages, and many of which have become college textbooks. Through his books, lectures, lessons, and videos, Ben has taught coding skills to over a million people. Ben lives in Oak Park, MI, with his wife Marcy and their children. He welcomes your emails at ben@forta.com and invites you to visit him online at http://forta.com/.


Shmuel Forta is an engineer, coder, maker, tinkerer, and teacher. He is a software developer at General Motors and has years of programming experience, including both writing

Trade Review
" This is the book I needed that I did not know I needed. Having taught myself Python and having taught students, there are still some gaps in my knowledge that Captain Code quickly filled. The overall design of the book is wonderful and easy to read. All of the questions I have normally had when it comes to Python are answered on the pages. The code is cleanly written and the ability to scan a QR code so you can copy the code digitally is a major time-saver. What is most evident about this book is that it has been written by people that have worked with students. Too often books are written for students by people who have never taught and it never translates well on the pages. Captain Code is accessible for students and teachers and I think it is a must have for any classroom that is exploring Python. I know I will keep one at home for me and a few more in the classroom." ---Nicholas Provenzano, TheNerdyTeacher, MACUL OutstandingTechnology Using Teacher of the Year, and ISTE Outstanding Teacher of the Year

Table of Contents
Introduction xv
PART I: IT'S ALL FUN AND GAMES 1
Chapter 1 Getting Started 3
Understanding Computer Programming 4
What is a computer? 4
How do we talk to computers? 5
What is Python? 8
Setting Things Up 9
Installing Python 9
Installing and Configuring Visual Studio Code 10
Creating a Work Folder 13
Writing Your First Python Program 15
Selecting Your Work Folder 16
It's Coding Time! 17
Summary 19
Chapter 2 Mad Libs 21
Understanding Functions 22
Using Variables 23
Creating a Variable 24
Using a Variable 24
Some Important Variable Rules 25
Variables, More Variables, and Even More Variables 26
Getting User Input 28
Playing Mad Libs 30
Write Your Story 30
Add Variables 30
Get User Input 32
Summary 33
Chapter 3 Roll the Dice 35
Using Libraries 36
The random Library 36
Generating Random Numbers 37
Choosing a Random Item 38
“3” Is Not 3 41
Commenting Your Code 43
One Die, Two Dice 45
Summary 49
Chapter 4 Calculate the Day 51
Working with Dates 52
The datetime Library 52
Using the datetime Class 55
Making Decisions 56
The if Statement 56
What else? 58
if Revisited 59
Testing for Other Options 61
Using in 62
Beating the Mathematician 63
Handling Numeric Inputs 63
Putting It All Together 64
An Alternate Solution 67
Summary 67
Chapter 5 Rock Paper Scissors 69
More Strings 70
Game Time 72
Handling User Input 72
The Game Code 74
One Last Tweak 76
Summary 77
Chapter 6 Secret Codes 79
Lists 80
Creating Lists 80
Accessing List Items 82
Changing List Items 83
Adding and Removing Items 84
Finding Items 85
Sorting 86
Loop-de-Loop 89
Looping Through Items 90
Looping Through Numbers 92
Nested Loops 93
Cracking the Code 95
Encrypting Characters 96
Modulus Math 97
Encryption Code 98
Decryption Code 102
Summary 104
Chapter 7 Guess the Number 105
Conditional Loops 106
Game Time 111
The Basic Game 111
Putting It All Together 116
Summary 120
Chapter 8 Becoming a Coder 121
How Coders Code 122
Have a Plan 122
Think Small 123
Game Components 124
Restricting User Input 125
Storing User Guesses 128
Displaying Lists 129
Masking Characters 131
Summary 136
Chapter 9 Hangman 137
Game Time 138
So How Does It Work? 141
Summary 148
Chapter 10 Keep Going 149
Birthday Countdown 150
Program Requirements 150
Program Flow 150
Some Tips 151
Tip Calculator 152
Program Requirements 152
Program Flow 153
Some Tips (Pun Intended) 153
Password Generator 154
Program Requirements 154
Program Flow 155
Some Tips 155
Summary 159
PART II: ON AN ADVENTURE 161
Chapter 11 Getting Func-ky 163
Functions Revisited 164
Creating a Function 165
Passing Arguments 167
Returning Values 171
Summary 175
Chapter 12 Exploring 177
Game Concept 178
Game Structure 179
Prompting for Options 181
Processing Options 182
Create a Work Folder 183
Game Time 184
Test It 189
Summary 191
Chapter 13 Cleanup Time 193
Optimizing Your Code 194
String Externalization 196
Creating the Strings File 196
Using Externalized Strings 200
Summary 201
Chapter 14 Reduce, Reuse, Recycle, Refactor 203
Understanding Refactoring 204
Identifying Refactoring Opportunities 205
Creating a User Choice Component 207
Designing a Reusable Component 208
Creating the User Options Function 213
Updating Your Code 218
Summary 221
Chapter 15 Carrying (and Using) Stuff 223
Planning the Inventory System 224
Creating a Dictionary 225
Working with Dictionaries 226
Lists of Dictionaries 228
The Inventory System 229
Creating an Inventory 230
Plugging In the Inventory System 232
Using the Inventory System 233
Displaying the Inventory 238
Summary 239
Chapter 16 Keeping It Classy 241
The Player System 242
Creating a Player Class 243
Creating the Class 243
Defining Properties 244
Creating Methods 247
Initializing the Class 250
Using Our New Class 251
Summary 255
Chapter 17 Color Your World 257
Installing Third-Party Libraries 258
Using Colorama 259
Importing and Initializing the Library 259
Coloring Your Output 260
Summary 264
Chapter 18 Keep Going 265
Health and Lives 266
Shopping for Items 271
Random Events 275
Battling Enemies 277
Saving and Restoring 280
Summary 282
PART III: RACING AROUND 283
Chapter 19 Crazy Driver 285
Introducing Pygame 286
Prepping the Game 286
Game Concept 286
Installing Pygame 288
Creating Work Folders 288
Obtaining Images 289
Getting Started 289
Initializing Pygame 290
Displaying Stuff 294
The Game Loop 295
Summary 300
Chapter 20 Image-ine the Possibilities 301
Files and Folders 302
Setting the Background 305
Placing the Cars 310
Summary 317
Chapter 21 We Like to Move It 319
Moving the Enemy 320
Moving the Player 323
Summary 327
Chapter 22 Crash, Bang, Boom 329
You Crashed, Game Over 330
Tracking Score 332
Increasing Difficulty 334
Summary 336
Chapter 23 Finishing Touches 337
Game Over Revisited 338
Pause 341
Varying Enemies 343
Ice Cubes 348
Summary 351
Chapter 24 Keep Going 353
Splash Screen 354
Scores and High Scores 354
Oil Slick 356
Multiple Enemies 357
And Then 358
Summary 359
What Next? 361
There's a Lot More to Python 362
Web Development 362
Mobile App Development 364
Game Development 364
And Then 365
Index 367
Bonus Online Chapter 25 Tinkering, Testing, and Debugging Revisited (Online Only)

Captain Code

    Product form

    £18.04

    Includes FREE delivery

    RRP £18.99 – you save £0.95 (5%)

    Order before 4pm today for delivery by Fri 26 Jun 2026.

    A Paperback / softback by Ben Forta, Shmuel Forta

      Trusted by thousands of customers. See 2,385+ Customer Reviews

      View other formats and editions of Captain Code by Ben Forta

      Publisher: Pearson Education (US)
      Publication Date: 16/02/2022
      ISBN13: 9780137653577, 978-0137653577
      ISBN10: 0137653573

      Description

      Book Synopsis
      Ben Forta is, first and foremost, an educator who has been teaching in some capacity since he was a teenager (many centuries ago). He is Adobe's Senior Director of Education Initiatives, and has more than three decades of experience in the technology sector in product development, support, training, and product marketing. Ben is the award-winning author of more than 40 books, some of which have been translated into 16 languages, and many of which have become college textbooks. Through his books, lectures, lessons, and videos, Ben has taught coding skills to over a million people. Ben lives in Oak Park, MI, with his wife Marcy and their children. He welcomes your emails at ben@forta.com and invites you to visit him online at http://forta.com/.


      Shmuel Forta is an engineer, coder, maker, tinkerer, and teacher. He is a software developer at General Motors and has years of programming experience, including both writing

      Trade Review
      " This is the book I needed that I did not know I needed. Having taught myself Python and having taught students, there are still some gaps in my knowledge that Captain Code quickly filled. The overall design of the book is wonderful and easy to read. All of the questions I have normally had when it comes to Python are answered on the pages. The code is cleanly written and the ability to scan a QR code so you can copy the code digitally is a major time-saver. What is most evident about this book is that it has been written by people that have worked with students. Too often books are written for students by people who have never taught and it never translates well on the pages. Captain Code is accessible for students and teachers and I think it is a must have for any classroom that is exploring Python. I know I will keep one at home for me and a few more in the classroom." ---Nicholas Provenzano, TheNerdyTeacher, MACUL OutstandingTechnology Using Teacher of the Year, and ISTE Outstanding Teacher of the Year

      Table of Contents
      Introduction xv
      PART I: IT'S ALL FUN AND GAMES 1
      Chapter 1 Getting Started 3
      Understanding Computer Programming 4
      What is a computer? 4
      How do we talk to computers? 5
      What is Python? 8
      Setting Things Up 9
      Installing Python 9
      Installing and Configuring Visual Studio Code 10
      Creating a Work Folder 13
      Writing Your First Python Program 15
      Selecting Your Work Folder 16
      It's Coding Time! 17
      Summary 19
      Chapter 2 Mad Libs 21
      Understanding Functions 22
      Using Variables 23
      Creating a Variable 24
      Using a Variable 24
      Some Important Variable Rules 25
      Variables, More Variables, and Even More Variables 26
      Getting User Input 28
      Playing Mad Libs 30
      Write Your Story 30
      Add Variables 30
      Get User Input 32
      Summary 33
      Chapter 3 Roll the Dice 35
      Using Libraries 36
      The random Library 36
      Generating Random Numbers 37
      Choosing a Random Item 38
      “3” Is Not 3 41
      Commenting Your Code 43
      One Die, Two Dice 45
      Summary 49
      Chapter 4 Calculate the Day 51
      Working with Dates 52
      The datetime Library 52
      Using the datetime Class 55
      Making Decisions 56
      The if Statement 56
      What else? 58
      if Revisited 59
      Testing for Other Options 61
      Using in 62
      Beating the Mathematician 63
      Handling Numeric Inputs 63
      Putting It All Together 64
      An Alternate Solution 67
      Summary 67
      Chapter 5 Rock Paper Scissors 69
      More Strings 70
      Game Time 72
      Handling User Input 72
      The Game Code 74
      One Last Tweak 76
      Summary 77
      Chapter 6 Secret Codes 79
      Lists 80
      Creating Lists 80
      Accessing List Items 82
      Changing List Items 83
      Adding and Removing Items 84
      Finding Items 85
      Sorting 86
      Loop-de-Loop 89
      Looping Through Items 90
      Looping Through Numbers 92
      Nested Loops 93
      Cracking the Code 95
      Encrypting Characters 96
      Modulus Math 97
      Encryption Code 98
      Decryption Code 102
      Summary 104
      Chapter 7 Guess the Number 105
      Conditional Loops 106
      Game Time 111
      The Basic Game 111
      Putting It All Together 116
      Summary 120
      Chapter 8 Becoming a Coder 121
      How Coders Code 122
      Have a Plan 122
      Think Small 123
      Game Components 124
      Restricting User Input 125
      Storing User Guesses 128
      Displaying Lists 129
      Masking Characters 131
      Summary 136
      Chapter 9 Hangman 137
      Game Time 138
      So How Does It Work? 141
      Summary 148
      Chapter 10 Keep Going 149
      Birthday Countdown 150
      Program Requirements 150
      Program Flow 150
      Some Tips 151
      Tip Calculator 152
      Program Requirements 152
      Program Flow 153
      Some Tips (Pun Intended) 153
      Password Generator 154
      Program Requirements 154
      Program Flow 155
      Some Tips 155
      Summary 159
      PART II: ON AN ADVENTURE 161
      Chapter 11 Getting Func-ky 163
      Functions Revisited 164
      Creating a Function 165
      Passing Arguments 167
      Returning Values 171
      Summary 175
      Chapter 12 Exploring 177
      Game Concept 178
      Game Structure 179
      Prompting for Options 181
      Processing Options 182
      Create a Work Folder 183
      Game Time 184
      Test It 189
      Summary 191
      Chapter 13 Cleanup Time 193
      Optimizing Your Code 194
      String Externalization 196
      Creating the Strings File 196
      Using Externalized Strings 200
      Summary 201
      Chapter 14 Reduce, Reuse, Recycle, Refactor 203
      Understanding Refactoring 204
      Identifying Refactoring Opportunities 205
      Creating a User Choice Component 207
      Designing a Reusable Component 208
      Creating the User Options Function 213
      Updating Your Code 218
      Summary 221
      Chapter 15 Carrying (and Using) Stuff 223
      Planning the Inventory System 224
      Creating a Dictionary 225
      Working with Dictionaries 226
      Lists of Dictionaries 228
      The Inventory System 229
      Creating an Inventory 230
      Plugging In the Inventory System 232
      Using the Inventory System 233
      Displaying the Inventory 238
      Summary 239
      Chapter 16 Keeping It Classy 241
      The Player System 242
      Creating a Player Class 243
      Creating the Class 243
      Defining Properties 244
      Creating Methods 247
      Initializing the Class 250
      Using Our New Class 251
      Summary 255
      Chapter 17 Color Your World 257
      Installing Third-Party Libraries 258
      Using Colorama 259
      Importing and Initializing the Library 259
      Coloring Your Output 260
      Summary 264
      Chapter 18 Keep Going 265
      Health and Lives 266
      Shopping for Items 271
      Random Events 275
      Battling Enemies 277
      Saving and Restoring 280
      Summary 282
      PART III: RACING AROUND 283
      Chapter 19 Crazy Driver 285
      Introducing Pygame 286
      Prepping the Game 286
      Game Concept 286
      Installing Pygame 288
      Creating Work Folders 288
      Obtaining Images 289
      Getting Started 289
      Initializing Pygame 290
      Displaying Stuff 294
      The Game Loop 295
      Summary 300
      Chapter 20 Image-ine the Possibilities 301
      Files and Folders 302
      Setting the Background 305
      Placing the Cars 310
      Summary 317
      Chapter 21 We Like to Move It 319
      Moving the Enemy 320
      Moving the Player 323
      Summary 327
      Chapter 22 Crash, Bang, Boom 329
      You Crashed, Game Over 330
      Tracking Score 332
      Increasing Difficulty 334
      Summary 336
      Chapter 23 Finishing Touches 337
      Game Over Revisited 338
      Pause 341
      Varying Enemies 343
      Ice Cubes 348
      Summary 351
      Chapter 24 Keep Going 353
      Splash Screen 354
      Scores and High Scores 354
      Oil Slick 356
      Multiple Enemies 357
      And Then 358
      Summary 359
      What Next? 361
      There's a Lot More to Python 362
      Web Development 362
      Mobile App Development 364
      Game Development 364
      And Then 365
      Index 367
      Bonus Online Chapter 25 Tinkering, Testing, and Debugging Revisited (Online Only)

      Recently viewed products

      © 2026 Book Curl

        • American Express
        • Apple Pay
        • Diners Club
        • Discover
        • Google Pay
        • Maestro
        • Mastercard
        • PayPal
        • Shop Pay
        • Union Pay
        • Visa

        Login

        Forgot your password?

        Don't have an account yet?
        Create account