1/144
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
Output (Python)
print()
Output (AP Pseudocode)
DISPLAY
What does output mean in programming?
Showing information to the user (on the screen)
What data type is 5?
int (integer)
What data type is 3.14?
float
What data type is "Hello"?
str (string)
What data type is True?
bool (Boolean)
Boolean values in AP pseudocode
TRUE and FALSE
What is a variable?
A named container that stores a value that can change
Python variable assignment symbol
=
AP pseudocode assignment symbol
←
Python is case sensitive means
Age and age are different variables
Rules for variable names
Start with letter/_ ; use letters/numbers/_ ; no keywords ; meaningful names
What is a string?
Text (characters) inside quotes
What is string concatenation?
Joining strings together using +
How do you concatenate strings in Python?
Use +
How do you add a space when concatenating?
Put " " between words in the concatenation
Why can’t you add a number to a string with + in Python?
Different data types; must convert number to a string
Convert a number to a string in Python
str(number)
What does input() return by default in Python?
A string
How do you get user input in Python?
variable = input("prompt")
How do you get user input in AP pseudocode?
variable ← INPUT("prompt")
How do you convert input to an integer in Python?
int(input("prompt"))
What is a comment?
A note for humans that the computer ignores
Python comment symbol
#
Purpose of comments
Explain code and make it easier to understand/debug
What is debugging?
Finding and fixing errors in code
Syntax error
Code is written incorrectly; program won’t run
Runtime error
Program runs until it crashes while executing
Logic error
Program runs but gives the wrong output
Overflow error
Too-large number for the allowed storage/type (too much info)
Roundoff error
Small inaccuracies caused by rounding decimals
Common debugging strategy: tracing
Step through code line by line and track variable values
Common debugging strategy: test cases
Try different inputs to check behavior
Arithmetic operators
+, -, *, / (and others like %, **)
Addition operator
+
Subtraction operator
-
Multiplication operator
*
Division operator
/
Python division returns
A float (decimal), even if dividing integers
Exponent operator in Python
**
Exponent operator in AP pseudocode
^
What is modulus?
Remainder after division
Modulus operator in Python
%
Modulus operator in AP pseudocode
MOD
What is 10 % 2?
0
What is 7 % 3?
1
If the first number is smaller in modulus (3 % 5)
The answer is 3
How to check if a number is even
number % 2 == 0
How to check if a number is odd
number % 2 == 1
Order of operations acronym
PEMDAS
PEMDAS order
Parentheses, Exponents, Multiply/Divide/Modulus, Add/Subtract
What is 5 + 3 * 2?
11
What is (5 + 3) * 2?
16
Comparison operators produce
Boolean values (True/False)
Equality operator in Python
==
Equality operator in AP pseudocode
=
Not equal operator in Python
!=
Not equal operator in AP pseudocode
≠ or !=
Greater than operator
>
Less than operator
Greater than or equal operator
=
Less than or equal operator
Logical operators combine
Boolean expressions
AND means
True only if both conditions are true
OR means
True if at least one condition is true
NOT means
Flips the truth value (True becomes False, False becomes True)
Why parentheses matter in logic
They change the order and meaning of the condition
Using RANDOM(a, b) in AP pseudocode
Returns a random integer from a to b inclusive
Python equivalent of RANDOM(a, b)
random.randint(a, b)
What is an algorithm?
A step-by-step set of instructions to solve a problem
What is a control structure?
A structure that controls the flow of a program
Sequence
Running statements in order from top to bottom
Selection
Choosing between paths using IF/ELSE
Iteration
Repeating steps using loops
IF statement purpose
Runs code only when a condition is true
ELSE purpose
Runs code when the IF condition is false
FOR loop purpose
Repeats a set number of times
WHILE loop purpose
Repeats while a condition stays true
Infinite loop
A loop that never stops because the condition never becomes false
Nesting
Putting a loop inside an if, or an if inside a loop, etc.
Most common nesting pattern
Loop through items and use IF to check each one
What is a list?
An ordered collection of items stored in one variable
Python list indexing starts at
0
AP pseudocode list indexing starts at
1
How to create a list in Python
name = [items]
How to create a list in AP pseudocode
name ← [items]
How to get list length in Python
len(list)
How to get list length in AP pseudocode
length(list)
Last index in Python
len(list) - 1
Last index in AP pseudocode
length(list)
Traversing a list means
Going through each item in the list
Python for-each traversal
for item in list:
AP pseudocode for-each traversal
FOR EACH item IN list
Searching a list common pattern
Use a found flag (found = False/TRUE)
Found flag purpose
Tracks whether the target value was found in the list
Add to end of list in Python
list.append(value)
Add to end of list in AP pseudocode
APPEND(list, value)
Insert into a list in Python
list.insert(index, value)
Insert into a list in AP pseudocode
INSERT(list, position, value)