Table of Contents
Introduction ix
The Flashcard App xi
Author's Note xiii
1 Hardware and Software 1
2 A Computer's Favorite Language - Binary! 5
Place Value 7
Binary Numbers Place Value 8
Converting Decimal Numbers to Binary 9
Converting Binary Numbers to Decimal 12
3 Getting Started 16
Iterative Software Development 19
4 Designing a Programming Solution: Algorithms 25
5 Pseudocode and Flowcharts 31
Pseudocode 32
Flowcharts 33
6 Writing and Commenting Our First Program 38
Let's Write Our First Program 40
Saving Our Program 42
Comments 44
7 Debugging and Testing 47
Testing 51
8 Variables and Assignment Statements 54
Assignment Statements 56
Variables in Assignment Statements 59
More Printing Options 60
9 Data Types 66
Converting Data Types, or "Casting" 69
How to Verify a Data Type 72
10 Math Symbols 75
Mathematical Operations 76
Modulus Math 77
Order of Operations 78
11 Strings 81
Index and Length 82
Concatenation 85
Immutable 87
Slicing 89
String Comparisons 92
String Built-in Functions 95
12 Input 99
User Input 100
Validate User Input 101
Reading and Writing Files 103
13 Three Types of Statements 109
Sequential Statements 110
Selection Statements 110
Repetitive Statements 111
14 Selection Statements 113
Boolean Values 115
Relational Operators 116
Format of the Selection Statement Condition 116
What Happens When the Condition Is False? 118
Multiple Possibilities-Nesting 120
15 Logical Operators 126
Logical Operator: and 127
Logical Operator: or 128
Logical Operator: not 129
Combining Logical Operators 129
16 Lists 133
How to Reference an item in a List 135
Lists: Length 136
Concatenation 137
Slicing 139
Processing lists 141
Lists: Frequently Used Built-in Functions 142
17 Repetitive Statements: while Loops 151
While Loops 152
While Loops: What Can Go Wrong? 154
While loops: What Else Could Go Wrong? 155
While Loops: Stopping in the Middle of an Iteration 156
While Loops: Continuing in the Middle of an Iteration 157
18 Repetitive Statements: for Loops 161
Strings and for Loops 163
For Loops and Lists 164
19 Function 168
Built-in Functions 169
Functions You Create 170
Parameters and Arguments 172
Global and Local Variables 175
Functions: The return Statement 178
20 Libraries and APIs 183
View Available Modules, Keywords, Symbols, and Topics 184
Modules Available with Python 186
How to Find or Create Modules to Share 186
Libraries and APIs 187
21 Projects 188
Project 1 Crazy Talk! 189
Project 2 Rock, Paper, Scissors 196
Project 3 Guess a Number 206
Project 4 Guessing Game Reboot! 213
Project 5 The Challenge Game 217
22 Micro:bit 227
Getting Started 228
Programming the Micro:bit 230
A Closer Look 232
Micro:bit Images 234
Making Your Own Images 235
Animating Images 236
Buttons on the Micro:bit 238
Micro:bit Pins 241
Micro:bit's Accelerometer 244
Micro:bit Gestures 246
Micro:bit Compass 247
Random Numbers 248
Words of Wisdom Game 252
Temperature Program 254
Starlight Program 256
Guess the Number Game 259
Catch the Falling Stars Game 262
Make Your Own Music 266
Follow the Leader Game 269
Answer Key 275