Symbols
= (assignment) operator, 57
== (equality comparison) operator, 57
// (division) operator, 48
/ (division) operator, 48
% (modulus) operator, 48, 97-98
# (pound sign), commenting, 214, 344
- (subtraction) operator, 48
* (multiplication) operator, 42, 48
A
antialiasing, 340
commas and, 31
naming, 168
range() function, 93
user-defined functions and, 167-170
variables and, 170
arrays, 212
ASCII code, 96
assignment operator (=), 57
asterisk (*), 42
attributes, 244. See also classes
B
battling enemies, 277-279. See also game(s); text-based adventure game(s)
birthday countdown
datetime variable, 151
program flow, 150
requirements, 150
blit() function, 309
bugs, 134
C
Call of Duty, 122
case sensitivity
color variables and, 291
choice() method, 73
dictionaries and, 243
instantiation, 246
player management system and, 251-255
reusability, 243
code(ing), 124
executing, 19
open source, 286
pseudo, 197
reuse, 174
string externalization, 196-201
unit testing, 125
whitespace, 25
stripping, 72
collide_rect() function, 331
collision detection, 330-331, 350-351
colons ( : ), 57
Colorama, importing and initializing the library, 259-260
Colossal Cave Adventure, 178
combining, import statements, 218, 307
commas, 31
computers, 5, 42. See also programming languages
communicating with, 6
microprocessors, 4
randomness and, 37
concatenation, 28, 42, 47, 130
conditional loops, 106-110, 115
conditions, 57
converting, strings to numbers, 65-66, 115
Crazy Driver. See also Pygame
adding multiple enemies, 357-358
collision detection, 330-331, 350-351
dynamic access to game files, 302-305
frame rate, 293
game area, 294
adding the high score, 354-356
increasing the difficulty, 334-336
obtaining images, 289
setting the background, 305-309
splash screen, 354
updating the display, 295
creating
new Python file, 17
user choice component, 207-208
variables, 24
CSS (Cascading Style Sheets), 363
curly braces ({ }), 225
D
data files, 362
data types, 43
datetime
variable, 151
decisions. See also loops
elif statement, 66
if statement, 56-58, 65, 66, 67, 73
indentation and, 58
nested, 77
decrypting messages, 102-103. See also encryption/decryption
def statement, 166, 167, 247. See also user-defined functions
dice
12-sided, 48
classes and, 243
functions and, 227
inventory system, 229-230, 233-237
displaying, 238
key:value pairs, 226
lists of, 228
updating, 227
dir() function, 246
display() function, 238
displaying, class properties, 246
E
editors, 7. See also IDEs (integrated development environments)
encoding, 95
encryption/decryption, 95, 96, 99-102
ASCII code, 96
equality comparison operator (==), 57
errors, in VS Code, 18
escape characters, 148
executing code, 19
Experience Design, 123
extend() function, 85
externalization. See also refactoring, string, 196-201
F
files. See also code(ing); game(s)
accessing dynamically, 302-305
creating, 17
data, 362
path, 302
saving, 27
test, 96
fill() method, 295
folders. See also work folder
creating
for loops, 90-91. See also loops
Crazy Driver, 297
iteration, 91
looping through numbers, 92-93
functions, 27, 164. See also classes; methods; variables
append(), 213
append() function, 274
blit(), 309
collide_rect(), 331
dictionary, 227
dir(), 246
display(), 238
extend(), 85
inputYesNo(), 221
join(), 305
list, 88
methods and, 54
move_ip(), 324
pop(), 85
print(), 28, 30, 31, 32, 46, 47, 55, 81, 84, 132-133
range(), 93
render(), 340
returning a value, 28
sleep(), 338
str(), 100
type(), 54
passing arguments, 167-170, 209
naming, 26
G
Colossal Cave Adventure, 178
Crazy Driver
adding multiple enemies, 357-358
collision detection, 330-331, 350-351
displaying the high score, 354-356
frame rate, 293
game area, 294
increasing the difficulty, 334-336
obtaining images, 289
setting the background, 305-309
development, 364
dynamic access to files, 302-305
files and, 302
folder structure, 302
graphics
antialiasing, 340
pixels, 294
updating the display, 295
displaying remaining lives, 147
masking characters, 131-136, 143
restricting user input, 125-128
inventory system, 233-237, 242-243
displaying, 238
player management system, 242-243
splash screens, 354
surface, 294
text-based adventure, 178, 184-188
health property, 266
loseHealth() function, 270-271
maxhealth property, 266
prompting for options, 181-182
Zork, 178
generating random numbers, 37-38, 46
getUserChoice() function, 213-217, 236
graphics
antialiasing, 340
pixels, 294
updating the display, 295
H
displaying remaining lives, 147
masking characters, 131-136, 143
restricting user input, 125-128
hard-coded values, 335
I
IDEs (integrated development environments), VS Code, 9
errors, 18
if statement, 56-58, 65, 66, 67, 127, 132
conditions, 57, 59, 60, 61, 115
elif and, 62
indentation and, 58
nested, 77
Rock, Paper, Scissors game, 74, 75
while statement and, 107
import statements, combining, 218, 307
incrementing variables, 119
initializing
lists, 82
input() function, 28, 38, 65, 102, 126. See also user input
inputYesNo() function, 221
installing
Pygame, 288
third-party libraries, 258-259
instantiation, 246
inventory system, 233-237, 242-243. See also player management system
displaying, 238
J-K-L
JavaScript, 363
join() function, 305
len() function, 81, 89, 110, 126, 212
libraries, 36
combining, 218
Flask, 363
naming, 200
os, 304
SDL, 287
string, 155
third-party, installing, 258-259
adding and removing items, 84-85
of dictionaries, 228
initializing, 82
of lists, 213
multiline, 142
syntax, 81
tuples and, 292
for loops, 101
loops, 89, 90. See also if statement
for, 101
while statement, 106-107, 108, 109, 110, 113, 143, 146
lower() method, 71
M
Mac users, creating a work folder, 14-15
user input, 32
append(), 345
choice(), 73
fill(), 295
lower(), 71
properties and, 55
strip(), 71
update(), 227
upper(), 71
microprocessors, 4
Microsoft Visual Studio Code. See VS Code
Minecraft, 122
mobile app development, 364
encryption and, 48
move_ip() function, 324
multiline
lists, 142
text, 200
N
naming
arguments, 168
files, 27
libraries, 200
variables, 26
nested if statement, 77
numbers
ASCII code, 96
O
open source software, 286
assignment, 57
division, 48
equality comparison, 57
multiplication, 48
subtraction, 48
ternary conditional, 249
os library, 304
Overwatch, 122
P
parentheses, calling a function, 53
passthrough variable, 173
password generator, 156
program flow, 155
requirements, 154
path, dynamic access to game files, 302-305
pixels, 294
plain text, 42
player management system, 242-243
pop() function, 85
pound sign (#), 214
print() function, 28, 29, 30, 31, 32, 46, 47, 55, 66, 81, 84, 132-133
programming languages, 5, 364. See also code(ing); IDEs (integrated development environments); Python
C#, 364
editors, 7
JavaScript, 363
Python, 9
creating a new file, 17
running code, 19
syntax, 8
programs. See also game(s)
birthday countdown
program flow, 150
requirements, 150
password generator, 156
program flow, 155
requirements, 154
tip calculator
program flow, 153
requirements, 152
properties, 244-246. See also variables
displaying, 246
initializing, 245
methods and, 55
pseudocode, 197
initializing, 290
installing, 288
updating the display, 326
Python. See also; classes; functions; methods; VS Code, 9
classes, datetime, 55
creating a new file, 17
creating a work folder
functions, 27
calling, 23
now(), 53
returning a value, 28
type(), 54
if statement, conditions, 57
libraries, 36
string, 155
adding and removing items, 84-85
initializing, 82
running code, 19
serializing/deserializing data, 280
syntax, 8
variables, 43
writing your first program, 15
selecting your work folder, 16-17
Q–R
QR codes, 9
random items
numbers
randrange() function, 38, 46, 346
range() function, 93
render() function, 340
restricting user input, 125-128
returning a value, 28
reusability
classes and, 243
creating a user choice component, 207-208
getUserChoice() function, 213-217
RGB (Red, Green, Blue) values, 291
Rock, Paper, Scissors, 72-74, 75, 76
rolling dice, 47
12-sided, 48
S
saving files, 27
scope, 174
SDL (Simple DirectMedia Layer) library, 287
serializing/deserializing data, 280
sleep() function, 338
splash screens, 354
spoken languages, programming languages and, 6-7
SQL, 363
storage, 224
dictionaries, 225
string, 201
str() function, 100
string library, 155
adding to, 158
case and, 71
converting to numbers, 65-66, 115
numbers and, 64
storage, 201
whitespace, stripping, 72
Stringtest.py, 70
strip() method, 71
stripping whitespace, 72
surface, 294
[ ] notation, 127
colons, 57
commas, 31
indentation and, 58
lists, 81
Python, 8
T
ternary conditional operator, 249
test files, 96
testing
code, 73
getUserChoice() function, 215-217
text-based adventure game, 189-190
unit, 125
text
externalizing, 196
multiline, 200
text-based adventure game(s), 178, 179, 184-188
Colossal Cave Adventure, 178
health and lives
health property, 266
loseHealth() function, 270-271
maxhealth property, 266
prompting for options, 181-182
testing, 189
Zork, 178
third-party libraries, installing, 258-259
three-dimensional arrays, 212
tip calculator
program flow, 153
requirements, 152
tuples, 292
two-dimensional arrays, 212
type() function, 54
U
unit testing, 125. See also testing
Unity, 364
update() method, 227
updating
dictionaries, 227
upper() method, 71
user choice component, creating, 207-208
Mad Libs, 32
user-defined functions, 165-167
V
values
constant, 156
constants, 157
hard-coded, 335
RGB (Red, Green, Blue), 291
user-defined functions and, 171-174
variables, 23-24, 30, 39, 40, 42, 43, 46
__file__, 303
concatenation, 28
creating, 24
data types, 43
datetime, 151
functions and, 53
importing, 299
incrementing, 119
initializing, 108
instantiation, 246
lists, 80
adding and removing items, 84-85
naming, 26
passthrough, 173
QUIT, 299
scope, 174
user-defined functions and, 170
whitespace, 25
VS Code. See also Colorama
colors, 25
comments, 45
creating a work folder, 13-15, 183-184
errors, 18
W
while loops, 106-107, 108, 109, 110, 113, 143, 146. See also conditional loops
if statement and, 107
Windows, 122
installing Python, 9
work folder
wrapper functions, 229-230, 234
writing your first program, 15
selecting your work folder, 15
X-Y-Z
x,y coordinate, 309
Zork, 178