Programming Basics and Computational Thinking

Course Learning Objectives & Reading Assignments

  • Core Learning Outcomes:

    • Describe the foundational elements of Computational Thinking.

    • Describe command line operation and hierarchical file system structures.

    • Create functional Python programs utilizing standard built-in functions.

    • Design and implement an algorithm capable of producing computer graphics and images.

  • Mandatory Reading Assignments:

    • "Introduction"

    • Downloading and Installing Python

    • "Chapter 19: Manipulating Images"

    • Computer Image Fundamentals

    • Assigned reading text: Automate the Boring Stuff with Python: Practical Programming for Total Beginners (2nd Edition) by Al Sweigart (No Starch Press). Over 500,000500{,}000 copies sold.


Automate the Boring Stuff with Python 2nd Edition

Program Development Cycle & Software Engineering Phases

  • Progression of Computing Concepts:

    • Software development progresses through a structured hierarchy: Natural Languages →\rightarrow Algorithm Design →\rightarrow Pseudocode / Flowcharts →\rightarrow Programming Languages →\rightarrow Compilation or Interpretation →\rightarrow Machine Languages.

  • Initial Problem-Solving Workflow:

    • Step 1: Use Natural Language to formulate a human-understandable strategy for solving the problem.

    • Step 2: Construct an algorithm using formal Pseudocode or Flowcharts to define logic and execution paths.

    • Step 3: Translate the algorithmic design into an executable program using a target programming language.

  • Definition of the Development Cycle:

    • The sequence of activities followed during the creation, testing, and subsequent evolution of a software solution.

    • In introductory computer science contexts where software evolution is secondary, the cycle is treated as a linear sequence of distinct phases.

  • Phases of the Software Development Cycle:

    • Phase 1 — Analysis: Investigating and defining the problem requirements and constraints.

    • Phase 2 — Design: Architecting the algorithmic logic, data representations, and function structure.

    • Phase 3 — Implementation: Writing source code in the chosen programming language to implement the designed algorithm.

    • Phase 4 — Testing: Running the program across various inputs and environments to detect and fix errors.

    • Phase 5 — Maintenance: Updating and refining software to repair bugs, improve performance, or meet changing requirements.


Software Development Cycle Diagram

Computational Thinking & Problem-Solving Methodologies

  • Definition of Computational Thinking:

    • A collection of problem-solving techniques specifically applied during the Design phase of the software development cycle.

  • The "Three A's" of Computational Thinking:

    • Abstraction: Isolating key principles and removing unnecessary complexities.

    • Automation: Formatting solutions into explicit, step-by-step procedures that can be executed automatically by a computer.

    • Analysis: Evaluating the performance, correctness, and efficiency of proposed solutions.

  • Detailed Elements of Abstraction:

    • Abstraction: Extracting only the relevant details needed to solve the problem while ignoring extraneous real-world specifics.

    • Decomposition: Splitting a complex software problem into smaller, independent subproblems. Frequently designated as the "Divide-and-Conquer" approach.

    • Pattern Recognition: Identifying similarities between current subproblems and previously encountered challenges to reuse verified solution patterns.

  • Practical Application of Divide-and-Conquer:

    • Deconstructing a master problem into easier subproblems allows each subproblem solution to be written as an independent function.

    • Because subproblem functions are modular, they can be reused across future projects.

    • Program execution across functions is coordinated by a single main() function.

  • General Four-Step Problem-Solving Framework:

    • Step 1 — Understanding the Problem: Brainstorming, analyzing geometric, color, and algorithmic constraints before writing any code.

    • Step 2 — Devising a Plan: Creating pseudocode or flowchart visual diagrams.

    • Step 3 — Carrying Out the Plan: Translating the plan into concrete Python source code.

    • Step 4 — Looking Back: Executing, validating, and testing the program output against expected requirements.

Command Line Interfaces, File Systems, & System Navigation

  • Command Line and Terminal Functionality:

    • Testing software during development requires a Terminal or Command Prompt interface.

    • A Command Prompt serves as a text-based system entry point, enabling users to perform system tasks, run scripts, and manage files without relying on a Graphical User Interface (GUI).

  • Hierarchical File Systems:

    • Operating systems structure storage directories in a tree-like hierarchy.

    • Every running process maintains a single active location known as the Working Directory.

    • The root directory in Unix/Linux systems is represented by a single forward slash /.

    • Initial working directory upon launching a Terminal in a Virtual Linux Environment is /home/student/, which contains standard user directories such as desktop and documents.


Linux File System Hierarchy Diagram
  • Windows Command Prompt Navigation Commands:

    • dir: Lists all files and subdirectories contained in the current working directory.

    • cd (without parameters): Prints the absolute directory path of the current working directory.

    • cd <path>: Changes the current working directory to the target path provided.

    • Relative Path ..: Refers to the parent directory located directly above the current working directory in the hierarchy.

  • Linux / Mac Terminal Navigation Commands:

    • ls: Lists all files and folders located in the current working directory.

    • pwd: Prints the absolute path of the working directory (Print Working Directory).

    • cd <path>: Navigates into the specified target directory.

    • Relative Path ..: Represents the parent directory directly above in the directory hierarchy.

Python Execution Modes & Program Architecture

  • Python Interpreter Modes:

    • Interactive Mode:

    • Triggered by entering python or python3 into the command line without arguments.

    • Evaluates Python statements sequentially, one line at a time.

    • Designed for rapid prototyping, quick testing, and evaluating single expressions.

    • Normal (Script) Mode:

    • Triggered by entering python (or python3) followed by a script file name (e.g., python script.py).

    • Sequentially executes every line of source code contained within the specified file.

  • Modular Program Architecture:

    • Functions (Procedures): Self-contained blocks of code engineered to solve specific tasks.

    • The main() Function:

    • Acts as the primary entry point governing overall program execution.

    • While strictly enforced in languages like C, C++, and Java, employing a main() function in Python is considered standard software engineering best practice.

    • Code Commenting:

    • Essential requirement for all created source code programs.

    • Explains program structure, function purposes, and algorithmic logic to improve readability and maintainability.

Standard Library Functions, Formatted Output, & String Interpolation

  • Function Calling Syntax & Terminology:

    • To call (execute) a function, write the function name followed by pair of round brackets ().

    • Values provided within the brackets are termed arguments.

    • Multiple arguments are supplied as a comma-separated list.

  • Built-in print() Function:

    • Produces textual output stream on the terminal screen.

    • Documentation reference: https://docs.python.org/3/library/functions.html

    • Formal Signature: print(*objects, sep=' ', end=' ', file=sys.stdout, flush=False)

    • Parameter Breakdown:

    • *objects: Variable positional arguments converted to text strings via str() and printed.

    • sep: Delimiter string placed between objects; default is a single space ' '.

    • end: Character string appended after all objects are printed; default is newline ' '.

    • file: Destination stream object (must have a write(string) method); defaults to sys.stdout. Text mode stream required (cannot print to binary mode file objects).

    • flush: Boolean flag specifying whether stream buffer is forcibly flushed; default is False. Added in Python version 3.33.3.

    • Calling print() with no arguments outputs only the end character string.

  • Formatted Printing Examples:

    • Standard multi-argument print: print("Hello", "World") produces Hello World.

    • Custom empty separator parameter: print("Hello", "World", sep='') produces HelloWorld.

    • Custom string separator parameter: print("Hello", "World", sep='′)‘produces‘Hello')` produces `HelloWorld.

  • String Interpolation via Formatted String Literals (F-Strings):

    • Created by placing an f or F immediately before the opening quotation mark of a string.

    • Variable names or Python expressions enclosed within curly brackets {} inside the f-string are evaluated at runtime and replaced with their corresponding values.

    • Comparison Example:

    • Given variable assignment code = 1405.

    • Without f-string prefix: print('Welcome to COMP{code}!') produces Welcome to COMP{code}!.

    • With f-string prefix: print(f'Welcome to COMP{code}!') produces Welcome to COMP1405!.

  • Python Standard Library & Pseudorandom Generator:

    • Standard Library: A collection of built-in modules (files containing Python functions and classes) that extend Python capabilities.

    • Import Directive: import random loads the random module into the program space.

    • random.randint(a, b): A function that accepts two integer parameters aa and bb and returns a pseudorandom integer nn fulfilling a≤n≤ba \le n \le b.

Algorithmic Problem Solving & Live Demonstration Projects

  • Case Study 1 — Dice Rolling Simulation:

    • Objective: Program a simulation of rolling unbiased, six-sided dice.


Unbiased Six-Sided Dice
  • Decomposition into Subproblems:

    • Subproblem 1: Generate a pseudorandom integer within the inclusive range [1,6][1, 6].

    • Subproblem 2: Display the generated integer to the user on the command prompt.

  • Mapping Subproblems to Existing Functions:

    • Subproblem 1 is solved using random.randint(1, 6) from the random module.

    • Subproblem 2 is solved using the built-in print() function.

  • Demonstration Source File: live_demo_01_roll_the_dice.py

Computer Graphics, Coordinate Systems, & Color Palettes

  • Case Study 2 — Artwork Reproduction:

    • Objective: Reproduce the abstract painting "Svanen (The Swan), No. 17" created by Hilma af Klint in 1915 using Python and the "Easy Graphics" library.


Svanen No 17 by Hilma af Klint
  • Demonstration Source File: live_demo_02_hilma_af_klint.py

  • High-Level Deconstructed Process:

    • Step 1: Instantiate a display window configured to the target dimensions.

    • Step 2: Fill the window canvas background with the exact shade of red.

    • Step 3: Draw concentric semicircles layering inward using exact specified color shades.

    • Display Window Coordinate System:

  • The display window origin (0,0)(0, 0) is anchored at the top-left corner of the screen.

  • The horizontal coordinate xx increases from left to right across the display width.

  • The vertical coordinate yy increases from top to bottom down the display height.

  • Exercise Canvas Specifications: Width = 500500 pixels, Height = 500500 pixels.

  • Center Canvas Coordinate: (250,250)(250, 250).


Computer Display Coordinate System
  • PICO-8 Standard Color Palette Reference:

    • Web Reference: https://www.reddit.com/r/pico8/comments/hhxvgs/palette_viewer_with_correct_hex_values/

    • Table of Color Indices, Names, and Hexadecimal Codes:

    • Index 00: BLACK (#000000)

    • Index 11: STORM (#102B53)

    • Index 22: WINE (#7E2553)

    • Index 33: MOSS (#008751)

    • Index 44: TAN (#AB5236)

    • Index 55: SLATE (#5F574F)

    • Index 66: SILVER (#C2C3C7)

    • Index 77: WHITE (#FFF1EB)

    • Index 88: EMBER (#FF0040)

    • Index 99: ORANGE (#FFA300)

    • Index 1010: LEMON (#FFEC27)

    • Index 1111: LIME (#00E43B)

    • Index 1212: SKY (#29ADFF)

    • Index 1313: DUSK (#83769C)

    • Index 1414: PINK (#FF77A8)

    • Index 1515: PEACH (#FFCCAA)

    • Index 128128: COCOA (#291814)

    • Index 129129: MIDNIGHT (#111035)

    • Index 130130: PORT (#422136)

    • Index 131131: SEA (#125359)

    • Index 132132: LEATHER (#742F29)

    • Index 133133: CHARCOAL (#493338)

    • Index 134134: OLIVE (#A28879)

    • Index 135135: SAND (#F3EF70)

    • Index 136136: CRIMSON (#BE1250)

    • Index 137137: CARROT (#FF6C24)

    • Index 138138: TEA (#ABE72E)

    • Index 139139: JADE (#00E543)

    • Index 140140: DENIM (#065AE5)

    • Index 141141: AUBERGINE (#754665)

    • Index 142142: SALMON (#FF6E59)

    • Index 143143: CORAL (#FF9081)

    • Important Caveat on Graphics Libraries: Not all colors present in external palette diagrams may be supported by a given library or environment; developers must thoroughly consult official library documentation.