Introduction to Problem-Solving and Python Programming

Fundamentals of Computer Science and Problem-Solving

  • Core Definition of Computer Science:

    • Computer Science is the systematic study of problems, problem-solving methodologies, and the solutions produced by this process.
    • It can be summarized fundamentally in two words: problem solving.
    • Given any problem, the primary objective is to design an algorithm capable of solving it.
  • Nature and Characteristics of Algorithms:

    • Definition: An algorithm is a step-by-step list of obvious, logical, sequential, and unambiguous instructions designed to solve a specific problem or perform a designated task.
    • Real-World Metaphor: An algorithm is functionally identical to a culinary recipe for preparing a specific food dish; sequentially following the predetermined steps leads directly to the completed dish or solution.
    • Essential Criteria:
    • Lucid, Precise, and Unambiguous: Every step must convey a single, unmistakable action.
    • Correctness: Must generate the correct solution under all possible valid test cases.
    • Finiteness: Must terminate and end after a finite number of operations.
  • Analysis of Algorithm Quality (Case Study: Area of a Rectangle Calculator):

    • Problem Formulation: Construct an algorithm to calculate the area of a rectangle where the user supplies the width and the height. Mathematical formula: Area=Width×Height\text{Area} = \text{Width} \times \text{Height}.
    • Solution A (Optimal / Good):
    • Step 1: Ask the user to enter Width.
    • Step 2: Ask the user to enter Height.
    • Step 3: Set Area to (Width×Height)(\text{Width} \times \text{Height}).
    • Step 4: Display Area for the user.
    • Assessment: Correct because its sequence is logical, explicit, and sequentially orderly.
    • Solution B (Defective – Lacks Explicitness):
    • Step 1: Ask the user to enter Width.
    • Step 2: Ask the user to enter Height.
    • Step 3: Calculate Area.
    • Step 4: Display Area for the user.
    • Defect: Step 3 fails to define the computational formula; the instructions are not obvious or explicit.
    • Solution C (Defective – Out of Sequence):
    • Step 1: Set Area to (Width×Height)(\text{Width} \times \text{Height}).
    • Step 2: Ask the user to enter Width.
    • Step 3: Ask the user to enter Height.
    • Step 4: Display Area for the user.
    • Defect: Width and Height have not been acquired or initialized prior to Step 1. They do not exist in memory at the time of calculation.
    • Solution D (Defective – Illogical Dependency on Undefined Entities):
    • Step 1: Set Area to (Width×Height)(\text{Width} \times \text{Height}).
    • Step 2: Display Area for the user.
    • Defect: Operates on undefined variables that are never declared, input, or assigned anywhere in the algorithm.
    • Solution E (Defective – Semantic / Logical Inaccuracy):
    • Step 1: Ask the user to enter Width.
    • Step 2: Ask the user to enter Height.
    • Step 3: Set Area to (Width×Height×2)(\text{Width} \times \text{Height} \times 2).
    • Step 4: Display Area for the user.
    • Defect: Calculates an invalid mathematical result. If Width=4\text{Width} = 4 and Height=5\text{Height} = 5, the algorithm outputs 4040 instead of the true value of 2020.

Program Design and the Development Lifecycle

  • Computational Limitations of Computers:

    • Computers lack independent cognitive intelligence and cannot deduce a solution spontaneously.
    • The human programmer must analyze the problem, formulate precise instructions, and instruct the computer to execute them.
  • The Two-Phase Software Engineering Model:Programming process

    • Problem-Solving Phase:
    • 1. Analysis and Specification: Understand and define the exact problem domain and identify the expected behavior of the solution.
    • 2. General Solution (Algorithm): Establish the necessary data structures, types, and sequence of operational steps.
    • 3. Verification: Trace and manually verify the algorithm step-by-step against test scenarios to confirm correct behavior before writing code.
    • Implementation Phase:
    • 1. Concrete Solution (Program): Translate the verified algorithm into a syntax-compliant programming language.
    • 2. Test: Execute the program on actual computational hardware and compare machine outputs against manual expectations.
    • 3. Maintenance Phase: Refactor and update existing code to accommodate evolving feature requests, adapt to new operating conditions, or patch bugs uncovered in live use.
  • Comprehensive Seven-Step Program Development Framework:

    • 1. Define the Problem: Segment requirements into Inputs, Processing Steps, and Outputs (IPO model).
    • 2. Outline the Solution: Decompose the overarching problem into modular, manageable sub-problems.
    • 3. Develop the Outline into an Algorithm: Expand the high-level outline into an explicit algorithmic sequence.
    • 4. Test the Algorithm for Correctness: Walk through edge cases before any coding occurs to catch logic errors early.
    • 5. Code the Algorithm: Implement the logic in a programming language (e.g., Python).
    • 6. Run the Program: Execute using a compiler or interpreter with specialized test cases to check for syntax, runtime, and logic errors.
    • 7. Document and Maintain: Add internal comments, write external documentation, and perform upkeep across the program's lifecycle.

Program Development Case Study: Simple Calculator

  • Functional Requirements:

    • The program accepts two integer values and an arithmetic operator (+ or −+\text{ or } -).
    • The program computes the correct result and displays the outcome to the user.
  • Technical Specifications:

    • Display a startup greeting: "Welcome to our Calculator".
    • Prompt the user for the first integer (XX).
    • Prompt the user for the second integer (YY).
    • Prompt the user to select an operator from the set {+,−}\{+, -\} (Sign\text{Sign}).
    • Calculate the outcome and print the resulting value on screen before exiting.
  • Algorithmic Formulation:

    • Step 1: Display a welcome message that says, "Welcome to our Calculator".
    • Step 2: Ask the user to enter the first number and save it to variable XX.
    • Step 3: Ask the user to enter the second number and save it to variable YY.
    • Step 4: Ask the user to select the sign (−,+-, +) and save it in variable Sign\text{Sign}.
    • Step 5: If Sign\text{Sign} is equal to "+", set Sum=X+Y\text{Sum} = X + Y.
    • Step 6: Otherwise, set Sum=X−Y\text{Sum} = X - Y.
    • Step 7: Display Sum\text{Sum}.
  • Pseudocode Representation: ```text

    1. print "Welcome to our Calculator"
    2. X = input "Enter the first number:"
    3. Y = input "Enter the second number:"
    4. Sign = input "Select - or +"
    5. if Sign is equal to "+" then:
    6. Sum = X + Y
    7. else:
    8. Sum = X - Y
    9. End if
    10. print Sum   ```
  • Flowchart Architecture:Flowchart for Simple Calculator

  • Step-by-Step Algorithm Verification:

    • Test Trace 1 (Addition Path):
    • Step 1: Print "Welcome to our Calculator".
    • Step 2: User provides X=20X = 20.
    • Step 3: User provides Y=10Y = 10.
    • Step 4: User provides Sign="+"\text{Sign} = "+".
    • Step 5: Evaluate conditional Sign == "+" →\rightarrow True (Yes).
    • Step 6: Compute Sum=20+10=30\text{Sum} = 20 + 10 = 30.
    • Step 7: Display 30.
    • Test Trace 2 (Subtraction Path):
    • Step 1: Print "Welcome to our Calculator".
    • Step 2: User provides X=50X = 50.
    • Step 3: User provides Y=15Y = 15.
    • Step 4: User provides Sign="−"\text{Sign} = "-".
    • Step 5: Evaluate conditional Sign == "+" →\rightarrow False (No).
    • Step 6: Compute Sum=50−15=35\text{Sum} = 50 - 15 = 35.
    • Step 7: Display 35.

Flowcharts, Pseudocode, and Problem Representation

  • Distinction Among Conceptual Forms:

    • Algorithm: The underlying logical set of steps required to solve a problem.
    • Pseudocode: A structured representation using English-like syntax that resembles programming code without adhering to strict language syntax rules.
    • Flowchart: A visual, geometric representation of sequential actions and control logic within a program.
    • Actual Source Code: Formal implementations in languages such as Python, C++, Java, or C.
  • Flowchart Elements and Standardized Symbols:

    • Oval (Terminator): Signifies the starting and ending points of an execution path (Start, End).
    • Parallelogram (Input/Output): Denotes data entry or output operations (e.g., input values, display messages).
    • Rectangle (Process): Represents internal operations, variable assignments, and arithmetic processing (e.g., addition, subtraction, division).
    • Diamond (Decision): Represents conditional branches evaluating to True or False (e.g., If/Then/Else structures).
    • Flowline (Directed Arrow): Shows the direction of logical flow through the system.
  • Practical Value and Scalability:

    • Flowcharts are less essential for programs with few lines of code, but they become critical when systems expand to hundreds of thousands or millions of lines of code.
    • Flowcharts provide a clear, high-level map of control logic, preventing architectural confusion.
  • Problem Walkthrough: Academic Grade Determination:

    • Problem Description: Calculate a student's final grade as the arithmetic mean of four scores, then report a status of "Pass" if the average is ≥60\ge 60, or "Fail" otherwise.
    • Algorithm:
    • 1. Ask the user to enter 4 marks (Mark1,Mark2,Mark3,Mark4\text{Mark1}, \text{Mark2}, \text{Mark3}, \text{Mark4}).
    • 2. Calculate the marks average (Avg\text{Avg}) by summing all marks and dividing by 44.
    • 3. If average (Avg\text{Avg}) is greater than or equal to 6060:
    • 4. Print "Pass".
    • 5. Else:
    • 6. Print "Fail".
    • 7. End if.
    • Pseudocode:text input Mark1, Mark2, Mark3, Mark4 Avg = (Mark1 + Mark2 + Mark3 + Mark4) / 4 if Avg >= 60: print "Pass" else: print "Fail" End if     
    • Verification Traces:
    • Test Scenario 1: Marks are 80,90,95,8580, 90, 95, 85.
      • Avg=80+90+95+854=3504=87.5\text{Avg} = \frac{80 + 90 + 95 + 85}{4} = \frac{350}{4} = 87.5
      • Condition: 87.5≥60→True87.5 \ge 60 \rightarrow \text{True}
      • Output: "Pass"
    • Test Scenario 2: Marks are 42,55,60,3742, 55, 60, 37.
      • Avg=42+55+60+374=1944=48.5\text{Avg} = \frac{42 + 55 + 60 + 37}{4} = \frac{194}{4} = 48.5
      • Condition: 48.5≥60→False48.5 \ge 60 \rightarrow \text{False}
      • Output: "Fail"
  • Problem Walkthrough: Length Conversion (Feet to Centimeters):

    • Conversion Ratio: 1 foot=30 cm1\text{ foot} = 30\text{ cm}.
    • Pseudocode:text LFT = input "Length in feet" LCM = LFT * 30 print LCM     
    • Test Trace:
    • Input: LFT=15\text{LFT} = 15
    • Processing: LCM=15×30=450\text{LCM} = 15 \times 30 = 450
    • Output: 450450
  • Problem Walkthrough: Area of a Rectangle:

    • Pseudocode:text input L, W A = L * W print A     

Decision Structures and Logical Branching

  • The If–Then–Else Selection Mechanism:Decision Branching Diagram

    • A logical expression (e.g., A>BA > B) evaluates to either true or false.
    • When the condition evaluates to true, control follows the left/true pathway.
    • When the condition evaluates to false, control follows the right/false pathway.
    • Structural Syntax:text if condition then true alternative else false alternative End if     
  • Relational Operators Reference Table:

    • > : Greater than
    • < : Less than
    • == : Equal to
    • >= (or ≥\ge) : Greater than or equal to
    • <= (or ≤\le) : Less than or equal to
    • != (or ≠\ne) : Not equal to
  • Problem Walkthrough: Determining the Largest of Two Values:

    • Pseudocode:
    Input VALUE1, VALUE2
    if (VALUE1 > VALUE2) then
        MAX = VALUE1
    else
        MAX = VALUE2
    endif
    print "The largest value is", MAX
    &nbsp;&nbsp;&nbsp;&nbsp;```
    * **Verification Traces:**
    * *Test Trace 1:* Inputs are VALUE1=3\text{VALUE1} = 3, VALUE2=5\text{VALUE2} = 5.
      * Check: 3>5→False3 > 5 \rightarrow \text{False}
      * Branch: MAX=VALUE2=5\text{MAX} = \text{VALUE2} = 5
      * Output: `"The largest value is 5"`
    * *Test Trace 2:* Inputs are VALUE1=50\text{VALUE1} = 50, VALUE2=80\text{VALUE2} = 80.
      * Check: 50>80→False50 > 80 \rightarrow \text{False}
      * Branch: MAX=VALUE2=80\text{MAX} = \text{VALUE2} = 80
      * Output: `"The largest value is 80"`
    * **Python Implementation:**
    

    python value1 = eval(input("Enter Value 1: ")) value2 = eval(input("Enter Value 2: "))

    if value1 > value2: largest = value1 else: largest = value2

    print("The largest value is", largest)     ```

Computer Architecture and Programming Languages

  • Computer System Fundamentals:

    • A computer is an electronic system engineered to store, retrieve, and process digital data.
    • Hardware: The physical, visible machinery and electronic components.
    • Central Processing Unit (CPU): Serves as the computational brain of the system; speed is measured in megahertz (MHz\text{MHz}) and gigahertz (GHz\text{GHz}).
    • Memory (RAM): Volatile primary storage accessed directly by the CPU.
    • Storage Devices: Non-volatile media such as magnetic disks, solid-state drives, and CDs.
    • Input Devices: Peripheral equipment such as keyboards and mice.
    • Output Devices: Visual and physical presentation units such as monitors and printers.
    • Communication Devices: Network devices including modems and Network Interface Cards (NIC).
    • Binary Foundation: Digital computers operate using binary states (00 and 11) because internal digital circuits have two stable physical voltage states.
    • Software: Programs consisting of instructions that direct the hardware to perform tasks.
  • Hierarchy of Programming Languages:

    • Machine Language: Low-level, primitive instructions coded directly in binary (00s and 11s). This is the only language a CPU can execute directly, but it is tedious and prone to error for humans.
    • Assembly Language: Low-level symbolic code that replaces raw binary with human-readable mnemonics; it requires an assembler to produce machine code.
    • High-Level Languages: User-friendly, English-like syntax that allows programs to run across different CPU architectures with minimal changes.
  • Catalog of Significant High-Level Languages:

    • Ada: Named in honor of Ada Lovelace; engineered for the United States Department of Defense, used in aerospace and defense operations.
    • BASIC: Beginner’s All-purpose Symbolic Instruction Code; built for novices learning programming.
    • C: Developed at Bell Laboratories; bridges low-level system power with high-level code structure and portability.
    • C++: An object-oriented language developed as an extension of C.
    • C#: Pronounced C Sharp; an enterprise hybrid language developed by Microsoft combining paradigms from Java and C++.
    • COBOL: COmmon Business Oriented Language; designed for business, enterprise data, and transaction processing.
    • FORTRAN: FORmula TRANslation; designed for high-performance numerical and scientific calculations.
    • Java: Developed by Sun Microsystems (later acquired by Oracle); built for platform-independent network and internet application deployment.
    • Pascal: Named for Blaise Pascal; a structured programming language widely used to teach clean coding practices.
    • Python: A modern, high-level, interpreted scripting language built for clear syntax and rapid development.
    • Visual Basic: Created by Microsoft to support rapid visual application development in Windows environments.
  • Source Code Translation Paradigms:

    • Terminology:
    • Statements: Individual directives written in a high-level programming language.
    • Source Program / Source Code: The full high-level program written by the programmer.
    • The Interpretation Process:Interpreting Source Code
    • An interpreter reads a single statement of source code, translates it into machine or virtual instructions, and executes it immediately before proceeding to the next line.
    • The Compilation Process:Compiling Source Code
    • A compiler parses and translates the entire source program into an executable machine-code file, which can then be run independently by an executor.

Python Overview and Environment Setup

  • Language Characteristics of Python:

    • General Purpose: Suitable for a wide range of software tasks, from basic scripting to large-scale data systems.
    • Interpreted: Python source files are interpreted and executed line by line at runtime.
    • Object-Oriented: Data is modeled through objects created from classes. A class acts as a template defining attributes and methods, supporting reusable code design.
  • Runtime Environments and Execution Modes:

    • Interactive Mode:
    • Code runs directly inside the interactive Python Shell (indicated by the >>> prompt).
    • Statements execute immediately when the user presses <Enter>, making it useful for testing single commands.
    • Script Mode:
    • Code is written into a text file saved with the .py file extension.
    • The interpreter parses and runs the full file from top to bottom, making this the standard approach for permanent programs.
    • Core Differences:
    • Script mode requires creating and saving a file before execution; interactive mode outputs results immediately.
    • Script mode allows structured code editing and saving; interactive sessions are ephemeral.
  • Integrated Development Environments (IDEs):

    • An IDE combines an editor, file explorer, runtime configuration, and debugger into a single application.
    • PyCharm: A dedicated Python IDE developed by JetBrains, available as a free, open-source Community Edition.
  • Configuring a Project in PyCharm:

    • Step 1: Open PyCharm.
    • Step 2: Select New Project.
    • Step 3: Provide a descriptive directory path and project name (e.g., "My First Project"), ensure a base Python interpreter is assigned, and click Create.
    • Step 4: Locate the project directory hierarchy on the left panel.
    • Step 5: Right-click the root project folder, choose New, then select Python File.
    • Step 6: Enter the file name without extension (e.g., Welcome), which creates Welcome.py.
    • Step 7: Enter source code into the editor workspace.
    • Step 8: Right-click within the editor tab and select Run 'Welcome' (or use the shortcut Ctrl+Shift+F10).
    • Step 9: Review program output in the bottom console panel.

Code Examples, Tracing, and Program Anatomy

  • Program Demonstrations:

    • Program 1: Displaying Two Messages (Listing 1.1 Welcome.py):
    # Display two messages
    print("Welcome to Python")
    print("Python is fun")
    &nbsp;&nbsp;&nbsp;&nbsp;```
    * *Execution Trace:* Line 1 is a comment and is skipped. Line 2 prints `"Welcome to Python"`. Line 3 prints `"Python is fun"`.
    * *Output:*
    

    text Welcome to Python Python is fun       ```

    • Program 2: Displaying Three Messages (Listing 1.2 WelcomeWithThreeMessages.py):
    # Display three messages
    print("Welcome to Python")
    print("Python is fun")
    print("Problem Driven")
    &nbsp;&nbsp;&nbsp;&nbsp;```
    * *Output:*
    

    text Welcome to Python Python is fun Problem Driven       ```

    • Program 3: Evaluating an Arithmetic Expression (Listing 1.3 ComputeExpression.py):
    • Problem: Compute the mathematical formula:       10.5+2×345−3.5\frac{10.5 + 2 \times 3}{45 - 3.5}
    • Implementation: python # Compute expression print((10.5 + 2 * 3) / (45 - 3.5)) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    • Output: 0.39759036144578314
  • Code Tracing:

    • Definition: A diagnostic technique where the programmer steps through code line by line, tracking variable values and output at each step.
  • Structural Components of Python Syntax:

    • Statements: Individual operational commands that perform an action (e.g., a print() call).
    • Indentation Rules:Indentation block structure
    • Python enforces block scope using indentation rather than braces.
    • Statements at the root level must begin in column 1 (no leading whitespace).
    • Unintended leading spaces produce an IndentationError.
    • No Terminal Punctuation: Python statements must not end with a semicolon or period; terminal punctuation causes syntax errors.
    • Case Sensitivity: Identifiers and built-in functions are case-sensitive; calling Print() instead of print() causes an error.
    • Comments:
    • Single-line comments: Preceded by the # symbol; the interpreter ignores all characters following it on that line.
    • Paragraph / Multi-line comments: Wrapped between triple single quotes (''' ... '''); the interpreter skips all content inside.
    • Special Characters Table:
    • () (Parentheses): Used with functions and expression grouping.
    • # (Pound sign): Marks the start of a single-line comment.
    • " " (Quotation marks): Encloses string literals.
    • ''' ''' (Triple quotes): Encloses multi-line paragraph comments.
  • Check Point Exercises:

    • Check Point 1 (Syntax Correction):
    • Broken Code:python # Display two messages print("Welcome to Python") print("Python is fun"). &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    • Errors Identified: Illegal leading whitespace on line 2, and an invalid trailing period on line 3.
    • Corrected Code:python # Display two messages print("Welcome to Python") print("Python is fun") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    • Check Point 2 (Output Prediction):
    • Given Code:python print("3.5 * 4 / 2 - 2.5 is") print(3.5 * 4 / 2 - 2.5) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    • Evaluation: Line 1 outputs literal text. Line 2 calculates: 3.5×42−2.5=14.02−2.5=7.0−2.5=4.5\frac{3.5 \times 4}{2} - 2.5 = \frac{14.0}{2} - 2.5 = 7.0 - 2.5 = 4.5.
    • Output:text 3.5 * 4 / 2 - 2.5 is 4.5 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

Code Style, Documentation Standards, and Error Handling

  • Programming Style and Documentation:

    • Programming Style: Enforces visual consistency so code is easy to read, review, and maintain.
    • Documentation: Explanatory text that outlines program intent, design decisions, and usage limits.
    • Commenting Best Practices:
    • Include a summary comment header stating the file's purpose, key features, and implementation details.
    • Academic programs should include: Name, Class Section, Instructor, Date, and Description.
    • Add brief inline comments before complex logic blocks; avoid redundant comments.
    • Indentation and Spacing Standards:
    • Use a standard 4-space indentation level for nested blocks.
    • Place spaces around mathematical and logical operators (e.g., write 20 + 50 rather than 20+50).
    • Use blank lines to visually separate logical sections of a program.
  • Classification of Programming Errors:

    • 1. Syntax Errors:
    • Occur when code breaks the grammar rules of the language (e.g., misspelled keywords, missing quotes, unclosed parentheses, or bad indentation).
    • Caught by the interpreter during parsing; halts execution immediately.
    • Example: print("Hello) raises SyntaxError: EOL while scanning string literal.
    • 2. Runtime Errors:
    • Occur during execution when the program attempts an impossible or invalid operation (e.g., dividing by zero or opening a missing file).
    • Causes abnormal program termination and displays an error traceback.
    • Example 1: print(1 / 0) raises ZeroDivisionError: division by zero.
    • Example 2: x = input(...); print(x + 1) raises TypeError: can only concatenate str (not "int") to str because input() returns string data.
    • 3. Logic Errors:
    • Occur when a program runs without crashing but produces incorrect or unintended results.
    • These are the hardest errors to detect because the interpreter cannot flag them.
    • Case Study: Fahrenheit to Celsius Conversion (Listing 1.4 ShowLogicErrors.py):
      • Intended formula: T(oC)=59×(T(oF)−32)T(^\text{o}\text{C}) = \frac{5}{9} \times (T(^\text{o}\text{F}) - 32)
      • Flawed code: python print("Fahrenheit 35 is Celsius degree ") print(5 / 9 * 35 - 32) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      • Result: Produces -12.555555555555554 instead of the correct value 1.6666666666666667 because multiplication takes precedence over subtraction.
      • Correction: Add parentheses around the subtraction: 5 / 9 * (35 - 32).
  • Systematic Debugging Methodology:

    • Definition: The process of isolating, identifying, and resolving bugs within software.
    • Four-Step Debugging Protocol:
    • 1. Reproduce the problem: Re-run the program to consistently observe the failure.
    • 2. Read the error message: Examine the traceback to find the exact line number and error type.
    • 3. Locate the cause: Inspect variable values near the target line (e.g., insert temporary print() statements).
    • 4. Fix and re-run: Apply the correction and re-test to confirm the issue is resolved.
    • Debugging Case Study (Listing 1.5 TotalPrice.py):
    price = 20
    quantity = 3
    total = price * quantity
    print("Total: $" + total)
    &nbsp;&nbsp;&nbsp;&nbsp;```
    * *Traceback:* `TypeError: can only concatenate str (not "int") to str` on the final line.
    * *Analysis:* The `+` operator cannot concatenate a string (`"Total: $"`) directly with an integer variable (`total`).
    * *Fix:* Cast the numeric variable using `str(total)`:
    

    python print("Total: $" + str(total))       ```

    • Corrected Output: Total: $60
  • Comprehensive Check Point Review:

    • Check Point 3:
    • Missing a closing quotation mark produces a Syntax Error.
    • Attempting to read a non-existent file produces a Runtime Error.
    • Computing the area when asked for the perimeter produces a Logic Error.
    • Check Point 4:
    • When a program halts with a TypeError, inspect the traceback first to locate the line number and mismatched types.
    • If a program finishes without crashing but returns an incorrect value, it has a Logic Error; find it using manual tracing or diagnostic print() statements.
    • To inspect a suspect variable midway through execution, add a temporary print() statement directly after assignment.