CS 150B Comprehensive Study Guide: Computer Science Fundamentals, Python Syntax, and Computing History
Computer Science Vocabulary & Key Terminology
Variable: A named container used for storing values in memory.
Casting: Converting a value from one data type to another (e.g., converting a string to an integer).
Interpreter: Translates human-readable code to machine code line-by-line as the program executes.
Operator: Performs operations such as addition or multiplication on values.
Function: A reusable block of code, created with the
defkeyword, that runs when called.Parameter: The placeholder variable listed in a function's definition.
Return: Ends a function call and sends a result back to the caller.
Name Error (Unassigned Variable Handling): The error raised when a program attempts to use a variable that has not been defined.
Data Representation & Number Systems
Data Types and Typing:
Evaluating
type("5")produces<class 'str'>because"5"is enclosed in double quotation marks, identifying it as a string data type.Floating-point numbers (
float) represent real numbers containing decimal points. For example,3.0is a float, whereas3is an integer,"3.0"is a string, andthreeis treated as a variable name or identifier.
Binary and Decimal Conversions:
Decimal to Binary Conversion ():
Deconstruct into powers of : .
Result in binary representation: .
Binary to Decimal Conversion ():
Expand binary positions: .
Bit Capacity:
To represent the decimal number in binary (), exactly bits are required, as .
Character Encoding Systems:
ASCII (American Standard Code for Information Interchange): Utilizes bits per character, enabling representation of unique characters.
Unicode: Developed to replace ASCII due to ASCII's inability to encode global non-English scripts, international characters, and modern symbolic sets such as emoji.
Python Operators, Expressions, and Variable Evaluation
Compound Assignment Operators:

Given code sequence:
python x = 5 x *= 3 x -= 5 x %= 7 print(x) Step 1: Initialize .
Step 2: Multiplication assignment
x *= 3evaluates to .Step 3: Subtraction assignment
x -= 5evaluates to .Step 4: Modulo assignment
x %= 7computes remainder of division , giving .Step 5:
print(x)outputs 3$.\n\n- **Operator Precedence and Floor Division**:\n - Evaluating the expression `print(2 ** 3 // 3)`:\n - Exponentiation operator (`**`) has higher precedence than integer floor division (`//`).\n - Step 1: Compute 2^3 = 8.\n - Step 2: Compute floor division 8 // 3 = 2.\n - Output printed is 2$.
Formatted String Literals (f-strings):

Given code sequence:
python score = 7 print(f"Next: {score + 3 * 2}") Expression evaluated inside interpolation braces
{score + 3 * 2}:Operator precedence performs multiplication before addition: 3 \times 2 = 6$.\n - Addition evaluates as score + 6 = 7 + 6 = 13$.
Output printed is
Next: 13.
Name Resolution and Errors:

Given code sequence:
python total = price * 2 print(total) Execution fails on the first line because
pricehas not been assigned a value or defined in scope, raising aNameError.
String Manipulation, Slicing, and Length Determination
Substring Slicing Mechanics:
Slicing notation
string[start:stop]extracts characters starting at indexstartup to, but not including, indexstop.Basic Slicing:

phrase = "data science" print(phrase[5:12]) ``` - Index sequence for `"data science"`: - `d`(0), `a`(1), `t`(2), `a`(3), ` `(4), `s`(5), `c`(6), `i`(7), `e`(8), `n`(9), `c`(10), `e`(11). - Slice `[5:12]` retrieves characters from index 5 through 11, resulting in `"science"`. - **Extended Slicing (String Reversal)**: python code = "12345" print(code[::-1]) ```
Specifying a step of
-1iterates backwards through the string, producing"54321".
Length Evaluation of Sliced Substrings:

Given code sequence:
python text = "programming" part = text[3:9] print(len(part)) Slice
text[3:9]extracts indices 3 through 8, yielding"grammi".Substring length formula for
[start:stop]is .len(part)prints .\n\n\n# Functions, Modular Design, and Program Execution Flow\n\n- **Function Definitions and String Operations**:\n \n - Given code sequence:\n ```python\n def initial(name):\n return name[0]\n\n print(initial("Ada") + initial("Babbage"))\n ```\n - `initial("Ada")` returns index 0: `"A"`.\n - `initial("Babbage")` returns index 0: `"B"`.\n - String concatenation `"A" + "B"` evaluates to `"AB"`.\n\n- **Multi-Function Composition and Execution Hierarchy**:\n \n - Given code sequence:\n ```python\n def get_hours(days):\n return days * 24\n\n def get_pay(hours, rate):\n return hours * rate\n\n def summary(days, rate):\n hours = get_hours(days)\n pay = get_pay(hours, rate)\n return f"{hours} hours = {pay}"\n\n print(summary(2, 15))\n ```\n - **Execution Tracing**:\n - Function definitions are loaded into memory first.\n - The first function to actively execute is `summary()`, initiated by the outer `print(summary(2, 15))` statement.\n - `summary(2, 15)` calls `get_hours(2)`, returning 2 \times 24 = 48.\n - `summary` assigns `hours = 48` and calls `get_pay(48, 15)`, returning 48 \times 15 = 720$$.summaryassignspay = 720and returns formatted string"48 hours = $720".Final printed output is
48 hours = $720.
Computing Principles & AI Concepts
DRY (Don't Repeat Yourself) Principle:
Core software architecture standard discouraging redundancy.
Violation: Manually duplicating or copy-pasting an identical 5-line logic sequence across multiple code sections instead of encapsulating that logic within a single, reusable function.
Input-Process-Output (IPO) Model:
Framework describing basic computational processing steps:
Input: Gathering user input (e.g., executing
input()).Process: Manipulating, transforming, or combining data (e.g., building a personalized greeting string from an input name).
Output: Presenting transformed results to the user (e.g., executing
print()).
Artificial Intelligence Concepts and Ethics:
Turing Test: Conceptual benchmark created by Alan Turing to evaluate whether a machine can exhibit conversational behavior indistinguishable from a human. A chatbot convincing human evaluators of its humanity in text communication exemplifies passing the Turing Test.
Skill Acquisition and Tool Dependency: Complete reliance on automated AI tools to solve programming exercises deprives students of active problem-solving practice necessary to build underlying conceptual models and coding proficiency.
Computing Pioneers & Historical Foundations
Ada Lovelace:
Authored the world's first computer algorithm intended for machine implementation.
Recognized as the first computer programmer.
Charles Babbage:
Conceptualized and designed the Analytical Engine, laying mechanical hardware foundations for modern computing architecture.
Alan Turing:
Developed foundational concepts of theoretical computer science and artificial intelligence.
Formulated the Turing Test and the theoretical Turing Machine model.
Grace Hopper:
Developed the first computer compiler, transforming symbolic programming instructions into machine code.
Championed machine-independent programming languages, laying the groundwork for English-like syntax in modern programming languages.