1/85
Looks like no tags are added yet.
Compiler
A special program that takes care of converting programs into binary machine code
Variable
Something that stores information in program so that it can be used later; An abstraction inside a program that can hold a value; each one of these has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values; using meaningful names for these helps with the readability of program code and understanding of what values are being represented
Algorithm
A self-contained step-by-step set of instructions to solve a problem (accomplish a task); can be expressed in a variety of ways, such as natural language, diagrams, or psuedocode; can be constructed using combinations of sequencing, selection, and iteration
String
An ordered sequence of characters
Concatenation
Joins together two or more strings end
Input Function
A function that prints a prompt and retrieves text from the user.
Mouse Events
When a user does something with a mouse like clicking or moving
Callback Function
A function that gets called by a program in response to some event
When should you use an integer?
When the value represents a whole number or something being counted, such as the number of students, number of tickets, or number of complete groups.
When should you use a float?
When the value can contain a decimal, such as a temperature, measurement, average, or price.
When should you use a string?
When the value represents text, such as a name, username, or message.
How do you choose the best data type for a variable?
Think about what kind of information the variable needs to store: a whole number, a decimal number, or text.
What makes a variable name appropriate?
It should clearly and specifically describe the value being stored.
Why are overly general variable names sometimes a problem?
They may not tell the reader exactly what information the variable represents.
When choosing between several reasonable variable names on an exam, what should you look for?
Choose the name that most precisely describes the specific value being stored.
What counts as user input?
Information the user directly enters or selects while using the program.
How can you tell whether something is user input?
Ask: "Would the person using the program need to enter or select this information?"
What data type does input() return?
A string.
If a user types 15 into input(), is the value automatically an integer?
No. It is initially the string "15".
What does int(input()) do?
It gets input from the user and converts that input into an integer.
What happens in age = int(input("Enter age: "))?
The program gets the user's input, converts it to an integer, and stores the integer in age.
Why would you convert user input to an integer?
So the program can use the value as a whole number in calculations.
What does float(input()) do?
It gets input from the user and converts it into a float so decimal values can be used in calculations.
Can int() convert the string "15" into an integer?
Yes. It becomes the integer 15.
Can int() directly convert the string "hello" into an integer?
No. "hello" does not represent a number that can be converted to an integer.
What happens when a value is assigned to a variable?
The value is stored in that variable.
What happens when a variable is reassigned?
Its old value is replaced by the new value.
If x = 5 and then x = 9, what is the final value of x?
9.
If x = 5 and then x = x + 2, what is the new value of x?
7.
How does x = x + 2 work?
The program uses the current value of x, adds 2, and then stores the new result back in x.
When evaluating an assignment statement, which side is calculated first?
The right side. The result is then stored in the variable on the left.
When tracing code, should you continue using a variable's original value after it has been reassigned?
No. Always use its most recently assigned value.
Trace: a = 4, b = 7, a = b. What are the final values of a and b?
a = 7 and b = 7.
Trace: x = 3, y = 8, x = y, y = x + 2. What are the final values of x and y?
x = 8 and y = 10
Trace: a = 10, b = 4, a = a + b, b = a
What is the safest way to trace several variables?
Go one line at a time and update each variable's value immediately when an assignment/reassignment occurs.
Operator Precedence
Tells us what mathematical operation to do FIRST in the following order: Parentheses ( ), Exponents **, Modulo/Multiplication/Division (equal priority, left to right), Addition/Subtraction (equal priority, left to right)
What does + do?
Addition.
What does
do?
What does * do?
Multiplication.
What does / do?
Regular division
What does // do?
Floor division
What does % do?
It returns the remainder after division.
What does ** do?
Exponentiation.
What is 2 ** 5?
32.
What is 17 / 4?
4.25.
What is 17 // 4?
4.
What is 17 % 4?
1.
If 93 students are placed into groups of 40, what does 93 // 40 equal?
2, because two complete groups of 40 fit into 93.
If 93 students are placed into groups of 40, what does 93 % 40 equal?
13, because 13 students remain after making two complete groups of 40.
If 135 tickets are exchanged in groups of 50, what does 135 // 50 equal?
2 complete groups.
If 135 tickets are exchanged in groups of 50, what does 135 % 50 equal?
35 tickets remaining.
If n % 3 = 0, what does that tell you?
n is evenly divisible by 3.
If a number is evenly divisible by another number, what is the remainder?
0.
Which happens first: multiplication/division or addition/subtraction?
Multiplication and division happen before addition and subtraction unless parentheses change the order.
What happens when two operations have the same precedence?
Evaluate them from left to right.
Evaluate 4 + 3 * 2.
Evaluate (4 + 3) * 2.
Evaluate 12
6 / 3.
Evaluate 6 * (10
3 * 2).
Evaluate 20 // 6.
3.
Evaluate 20 % 6.
2.
Evaluate 14 % 5 + 2.
Evaluate (19 % 5) + 1.
What is the best way to avoid mistakes on a long mathematical expression?
Work through one operation at a time using the order of operations instead of trying to calculate the entire expression mentally.
Why are parentheses important when substituting expressions?
They preserve the grouping and order of operations from the original code.
Suppose a = 12
4, b = 18 / 3, and c = a + 2 * b. What single expression represents c?
When comparing several expressions to a multi
line program, what should you calculate first?
If one supplied procedure appears inside another (nested), which should you evaluate first?
The inner procedure.
If a supplied procedure has multiple arguments, does their order matter?
Yes. Match each argument to its position in the procedure definition.
When creating a circle on a coordinate graph, what do the x and y values represent?
The center point of the circle.
If a circle has x = 3 and y = 5, where is its center?
(3, 5).
What does the radius of a circle measure?
The distance from the center of the circle to its edge.
Is the radius the distance all the way across the circle?
No. The distance all the way across is the diameter.
How are radius and diameter related?
The diameter is twice the radius.
A circle is centered at (4, 6) with a radius of 2. What does that tell you?
The center is at (4, 6), and the edge of the circle is 2 units away from the center.
In the point (3, 7), what is x and what is y?
x = 3 and y = 7.
If xVal = 4, what is xVal + 2?
6.
If xVal = 4 and yVal = 5, what point is (xVal, yVal + 2)?
(4, 7).
If xVal = 4 and yVal = 5, what point is (xVal + 2, yVal)?
(6, 5).
If xVal = 4 and yVal = 5, what point is (xVal + 2, yVal
3)?
How should you solve a graph question containing variables inside coordinates?
Substitute the variable values and calculate the actual coordinates before comparing them with the graph.
What should you do when an FRQ says IDENTIFY?
State the requested information directly and accurately.
What should you do when an FRQ says DESCRIBE?
Give details about what something is or what it does, including how the relevant expression determines its value.
What should you do when an FRQ says EXPLAIN?
Connect cause and effect. Show how or why one part of the program leads to the requested result.
What's the difference between DESCRIBE and EXPLAIN on these FRQs?
Describe tells what the expression does and how it determines the value. Explain connects that value to what happens in the program or what is displayed.