CoPro1 HN Sem 1 Exam Study Guide

General Programming Concepts

  • Class: A blueprint for creating objects with specific attributes and methods.

  • Constructor: A method used to create an instance of a class.

  • Object: An instance of a class with properties and behaviors.

  • Instance: A specific realization of a class.

  • Signature: The parameters required for a constructor or method.

  • Attribute: A variable contained within an object.


Accessors and Mutators

  • Accessor: A method that retrieves or "gets" an object's attribute.

  • Mutator: A method that changes or "sets" an object's attribute.


Color

  • Color: A class used to create color objects using RGB values or color names.

  • Red (R): The red component of an RGB color.

  • Green (G): The green component of an RGB color.

  • Blue (B): The blue component of an RGB color.


Random Values

  • Random: A Python module used to generate random numbers.

  • randint(): Returns a random integer between two inclusive values.

  • randrange(): Returns a random number in a specified range, but the end is exclusive.

  • Inclusive: Includes the boundary value.

  • Exclusive: Does not include the boundary value.


Expressions and Conditionals

  • Expression: A combination of values, variables, and operators that evaluate to a value.

  • Conditional: Code that runs only if a specific condition is met.

  • Boolean: A data type with two possible values: True or False.

  • Comparison Operators: Operators used in expressions to compare values, including:

    • < (less than)

    • > (greater than)

    • <= (less than or equal to)

    • >= (greater than or equal to)

    • == (equal to)

    • != (not equal to)


Control Flow (If Statements)

  • if-statement: A conditional statement that executes a block of code if a condition is True.

  • elif-statement: A conditional statement that follows an if, executed if the if condition is False and its condition is True.

  • else-statement: Executes a block of code if all previous if and elif conditions are False.

  • and: Logical operator that requires both conditions to be True.

  • or: Logical operator that requires at least one condition to be True.


Functions and Methods

  • Function: A block of code that performs a specific task when called.

  • Method: A function that belongs to an object and is called on that object.

  • Parameter: A variable used in a function definition to accept input.

  • Return: A value that a function sends back to the caller.


Contains and Overlaps Methods

  • Contains Method: Determines if a point (like the mouse) is inside an object.

  • Overlaps Method: Checks if two objects are touching or overlapping.


Loops

  • Loop: Repeats a block of code while a condition is True.

  • While Loop: A loop that continues to execute as long as a specified condition is True.

  • For Loop: A loop that iterates over a range or a list of items.

  • Range(): A function used to generate a sequence of numbers.

  • Iteration: A single pass through a loop.

  • Indexing Variable: A variable used to keep track of a position in a loop (often i or j).


Text

  • Text: A class in pyDraw used to create and display text on the screen.

  • String: A sequence of characters enclosed in quotes (e.g., 'Hello', "World").


Lists

  • List: A data structure that stores multiple items in a single variable.

  • Index: The position of an element in a list (starting from 0).

  • Element: An individual item in a list.

  • List Construction: The process of creating a list using square brackets (e.g., [1, 2, 3]).


List Methods / Functions

  • append(): Adds an element to the end of a list.

  • count(): Counts how many times a specified value appears in a list.

  • index(): Returns the position of the first occurrence of a specified value in a list.

  • insert(): Adds an element at a specified index in a list.

  • pop(): Removes and returns an element from a specified position in a list.

  • remove(): Removes the first occurrence of a specified value from a list.

  • len(): Returns the number of elements in a list.


Algorithms

  • Algorithm: A step-by-step set of instructions to solve a problem.

  • Centering Algorithm (Two-step): A method to center an object inside another object using relative positioning.

  • Centering Algorithm (Single-step): A simpler way to center an object using the .center() method.

  • Odd/Even Check: Uses modulus (% 2) to check if a number is odd or even.

  • Bouncing Object Algorithm: Changes the direction of an object when it hits the screen edge.


Symbols and Operators

  • <: Less than.

  • >: Greater than.

  • <=: Less than or equal to.

  • >=: Greater than or equal to.

  • ==: Equal to.

  • !=: Not equal to.

  • %: Modulus operator (remainder of a division).

  • +: Addition operator.

  • -: Subtraction operator.

  • *: Multiplication operator.

  • /: Division operator.

  • =: Assignment operator.

  • +=: Increment operator (adds a value to a variable).