1/69
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Algorithm
An ordered set of clearly defined instructions used to accomplish a specific task. The expression of any task as a sequence of detailed steps is an algorithm.
Algorithmic Thinking
The process of solving problems by identifying the tasks required to solve a problem and using algorithms to clearly describe each task. This is an acquired skill that takes practice and repetition.
Program/Software
A collection of program statements that performs a specific task when run by a computer.
Input and Output (I/O)
An algorithm or program can be designed to accept information, known as input. The program processes this input and produces an output, which is the result.
Natural Language
An ordered list of steps expressed in a spoken language, such as English or Spanish.
Flowcharts
A diagram that shows a sequence of steps using standardized shapes (rectangles for actions, rhombuses for decisions) and arrows to show the flow of the algorithm.
Pseudocode
A written set of instructions that follow a certain structure, looking more like code, but cannot be executed by a computer.
Programming Language (e.g., Python)
A structured set of instructions with special keywords and formatting that can be interpreted and executed by a computer or digital device. Clarity and readability are important in this method.
Variable
A place inside a program that can hold a value. Each variable has associated data storage that represents one value at a time.
Assignment Operator (=)
Used to assign a value to a variable (e.g., user_name = "student"). Note that = does not imply mathematical equivalence. (The College Board uses the arrow symbol ← to represent assignment).
Sequential Execution
Programs are executed sequentially, from the first statement to the last. The value of a variable at the time a statement is executed is what is used for that calculation; changing the variable later does not affect previously executed code.
Variable Naming Conventions (Recommended)
Start variable names with a lowercase letter, and use underscores to separate words (e.g., num_turtles).
String
A sequence of characters. The data returned by the input() statement is always a string data type by default, even if a user enters a number. Strings cannot be used in calculations.
Integer (int)
A numerical data type.
Type Conversion
To convert a string value (e.g., from input()) to a number (integer) for calculations, the int() function is used (e.g., num = int("100")).
Modulo Operator (%)
Calculates and returns the remainder of a division problem. It is commonly used to determine if a number is odd (remainder 1) or even (remainder 0, using 2 as the divisor).
Relational Operators
Used to compare two values, resulting in a true or false (Boolean) value.
==
equal to
!=
not equal to
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
Order of Operations (PEMDAS)
The computer follows the order of operations to execute arithmetic expressions. Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. Multiplication (*), Division (/), and Modulo (%) have the same precedence and are performed from left to right. The dot operator (e.g., in painter.right(5)) is evaluated after parentheses and before any mathematical operators.
Turtle Module
A Python file containing predefined, reusable code that provides drawing functionality. It is imported using import turtle as trtl.
Turtle Object (e.g., painter)
An instance of the class that you manipulate on the screen.
Methods
Instructions for the turtle, called using the dot operator (.) (e.g., painter.forward(d)). Methods often accept parameters (values in parentheses) to specify exact behavior.
.forward(d)
Moves the turtle in the direction it is facing for a distance of d pixels, distance (d)
.right(a)
Turns the turtle to the right by a degrees, angle (a)
.pensize(s)
Sets the size of the line drawn by the pen, size (s)
.pencolor(c)
Changes the color of the drawing pen, color name (c) (e.g., "red")
.penup()
Lifts the pen off the canvas (stops drawing lines), None
.pendown()
Places the pen back on the canvas (resumes drawing), None
.turtlesize(s)
Sets the size of the turtle object, size (s)
.setheading(h)
Sets the direction the turtle is facing (0 to 360 degrees) ,heading (h)
.goto(x, y)
Moves the turtle to the specified coordinates, x and y locations
.xcor()/.ycor()
Returns the current x or y coordinate of the turtle, None
Turtle Coordinate System
The screen uses the traditional coordinate plane with the center at the origin (0, 0). The turtle starts facing the positive x-direction (heading 0 degrees).
circle(r, e, s) Method
Can be used to draw circles, arcs, and polygons.
r (radius)
Specifies the radius (required).
e (extent/angle)
Specifies the angle of the arc to be drawn (e.g., 180 draws a semicircle).
s (segments/steps)
Specifies the number of segments, which can make the circle look like a polygon (e.g., 5 segments draws a pentagon).
.fillcolor(c)
Specifies the color to fill the inside of a shape.
.begin_fill()
Specifies the start of the shape that will use the fill color.
.end_fill()
Specifies the end of the shape.
Class
Like a blueprint or recipe.
Object
An instance of a class (e.g., painter is an object of the Turtle class).
Properties
The characteristics of an object (e.g., color or size).
Methods
The actions that an object can take (e.g., .circle(r) or .forward(d)).
Iteration
executing a block of statements or a code segment multiple times.
range(start, stop, step)
Generates a sequence of numbers. start: Optional starting point (default 0). stop: Specifies the number that ends the sequence; it will not be included in the sequence. step: Optional number to increment by (default 1).
Zero Iteration Condition
A loop never starts because the initial condition evaluates to False.
Infinite Loop
A loop that executes indefinitely because the condition remains True.
Conditional Statement (if)
Executes an indented block of statements only if the specified condition evaluates to True. This process is called selection.
else Clause
Executes when the preceding if condition (or elif conditions) is not met (False). It serves as a catch-all.
elif Statement
Executes only after the previous if or elif conditions have evaluated to False AND its own condition evaluates to True. If a condition is matched in an if/elif structure, the rest of the conditions are ignored.
Nested Conditionals
An if statement placed inside another if statement, allowing multiple conditions to be tested at once.
Nested Loop/Nested Iteration
Placing a loop inside another loop. Example structure: outer loop -> inner loop. Each time the outer loop iterates once, the inner loop runs to completion. This is a powerful construct because it can iterate tasks millions of times.
List
A construct used in Python to group similar types of items together. Items are separated by commas and are called elements. Lists are created using square brackets ([]).
List Iteration
A for loop can iterate through a list, retrieving each element and assigning it to the loop variable for processing.
.append(value)
Adds a new element to the end of the list. [ex - my_list.append("pasta")]
.pop()
Removes the last element from a list. The removed value can optionally be assigned to a variable. [ex last_item = my_list.pop()]
.remove(element)
Searches for a specific element in the list and removes it. [my_list.remove(my_turtle)]
Bugs
Imperfections and errors in code.
Hand Tracing with a Trace Table
A debugging technique used to follow a program step-by-step by recording the values of variables in a table after each line of code is executed. This helps predict variable values during sequential execution.
Debugging Techniques
Effective ways to find and correct errors include Using test cases. Hand tracing. Using print statements to observe variable values and how they change. Using visualizations and debuggers (if available).
Multiline Comments
Triple single quotation marks ('''...''') can temporarily deactivate large sections of code during debugging. Permanent comments should use the hash symbol (#).
Reusing Algorithms
Using existing algorithms (like the one for determining odd/even numbers using modulo) as building blocks can reduce development time, reduce testing, and simplify error identification.
Collision Detection
To determine if objects (turtles) are too close, you need their current coordinates (.xcor() and .ycor()).
Absolute Value (abs())
Used to calculate the distance between coordinates. For example, abs(x1 - x2) determines the distance between the x-coordinates of two turtles.