MMS 1-4-1 Session Notes: Error Handling, File I/O, Project Details, and Exam Prep
Session Notes: MMS 1-4-1 — Error Handling, File I/O, Project Discussion, and Exam Prep
Time and scope
Session started around 10:05 with topics 7 and 8; topics beyond what's in modules were minimal.
Plan: discuss examples/modules, review the demo method, then cover the midterm exam.
For knowledge-base questions, the instruction was to trace rather than post full answers.
Extra credit policy and grading fairness
Error handling: extra credit opportunity available to all students, not just a subset.
Policy: extra credit is 5 points added to the entire component of the exercises (not a separate subcomponent).
Rationale: avoid unfairness; if offered to some, must be available to all.
Emphasis: extra credit is a chance to gain, not punishment; grades are revisited across the board.
Reflections on programming for multimedia students
The instructor reflected on how programming complements artistic work and structured thinking.
Comments vs. descriptive descriptions of code: creative students can turn code comments into a narrative of their programming journey.
Observations about students from different backgrounds (computer science/IT vs. creative disciplines) and how they express understanding through comments.
Contemplation of opening an open-distance learning paper about programming mindsets in multimedia studies.
About the project overview (prelude to live demo)
Project: a simple game (Number Guessing) with name entry and a limited number of attempts to guess a secret number.
Secret number generation: a random number between 1 and 100 inclusive.
User flow:
Enter name → receives a message that a secret number in [1, 100] has been generated.
User inputs guesses (integers); non-integer input triggers error handling.
Values outside the range (e.g., -1 or 101) trigger range handling; still counted as an attempt.
Feedback after each guess (higher/lower) to guide the user toward the secret number.
If a correct guess is made, display a congratulatory message and show the number of attempts, then return to the main menu.
High scores: displayed by a separate option; the higher-ranking game is the one with the fewest attempts.
Data persistence: high scores are stored in a file to persist across executions.
Project specifications and key terminology
Core components:
A score dictionary to track high scores across games.
A game function that accepts a score dictionary as a parameter.
Score dictionary concepts:
Suggested structure: a dictionary where the key is a tuple (game_number, name) and the value is the number of attempts, e.g.:
Alternative approach: a dictionary where the key is the game number and the value is another dictionary containing
name and attempts, depending on design choice.Example narrative for keys/values:
Game 1: (1, "Alex") -> 3 attempts; Game 2: (2, "Maria") -> 5 attempts; etc.
Access patterns:
Accessing an entry by key: e.g., scoredictionary[(gamenumber, name)].
If you need a list of top scores, you sort by the attempts value (ascending).
General guidance:
Keys can be tuples or nested dictionaries; whichever is chosen, ensure consistency.
You may use a sample “entry dictionary” structure for exercises: code, description, grade, units, etc., for a different exercise context.
Detailed game flow and technical notes
Menu options:
Play game: runs the main game loop.
View high scores: shows the current standings from the score dictionary and the persistent file.
Exit: quits the program.
Game loop specifics:
Input validation: ensure input is an integer; non-integers raise a ValueError, caught via try/except.
Range validation: if guess not in [1, 100], treat as an error case and count as an attempt (as per instructor’s clarification).
Feedback: after each valid guess, indicate whether the secret is higher or lower than the guess.
End condition: correct guess; show secret number and the number of attempts used.
Data storage and persistence:
High scores are saved to a file so they persist when the program terminates and restarts.
File-related notes were covered separately (see “Files and error handling” section).
Error handling and file I/O fundamentals (basics reviewed in class)
Two core file operations: writing and reading.
Text files are used for simplicity; many file types exist (CSV, JSON, binary), but text is foundational for learning.
File flow: program -> file for writing; file -> program for reading.
Databases are the evolution of file storage; databases enable structured queries, validation, and security; MMS 1-4-4 will tackle databases later.
Opening a file (open) and closing it (close) are essential to prevent data loss.
Modes of opening a file (for text files):
Read:
Write: (overwrites if exists; creates if not)
Append: (preserves existing content, adds to end)
Existence handling: reading from a non-existent file triggers an error; writing creates the file if it doesn’t exist.
Writing mechanics: use file.write(…) instead of print(…) to store data in the file; write adds raw strings to the file with control characters like \n for new lines.
Reading mechanics:
file.read() reads the entire content as a string.
file.read(n) reads the next n characters.
file.readline() reads one line at a time.
file.readlines() reads all lines into a list of strings.
The ordinary typical workflow: open a file, perform read/write, then close it.
Error handling with files:
Use try/except to catch FileNotFoundError or I/O errors and present user-friendly messages.
The with statement (context manager) can replace explicit open/close:
Example pattern: with open('filename', 'r') as f: …
Automatically closes the file after the block; no explicit close needed.
Practical demo references in the session:
Presidents.txt example: contrast between write mode (overwrites) and append mode (adds) when writing data.
Reading examples included: reading by character, by line, and reading all lines as a list and iterating over it.
Error handling in the exam and topic scope
The midterms include multiple-choice questions and tracing tasks (e.g., trace execution of code snippets).
Topic coverage included: error handling concepts, file I/O basics, dictionaries, and basic algorithmic logic (loops, conditionals).
The instructor emphasized preventing AI from solving exercises wholesale and keeping tasks aligned with taught handouts.
The final will mirror the midterm in format, and there will be three-day windows for finals (examples given: September 4, 5, 6).
Midterm/Final exam prep: sample questions and themes (as discussed in the session)
Function definition and argument syntax: correct Python syntax for a function with two arguments.
Trace-based questions: predict outputs for given loops with range, modulo, and conditionals.
Loop and indexing questions:
For loops with nested ranges; understanding how many iterations occur and how results are accumulated.
Conditional and switch-like logic: Python's match-case and default branches; behavior when no case matches.
Operators and boolean logic:
Equality operator:
==Between checks: x between 1 and 10 inclusive vs exclusive; correct formulation is .
Not operator and its effect on boolean expressions.
Local vs global scope and variables in functions:
Local variables are those declared inside a function.
Pseudocode versus actual Python code: pseudocode used for outlining algorithms; true Python code implements the logic.
Data types and structures:
Strings (STR) and character sequences; how to treat true/false booleans.
The difference between actual parameters (arguments supplied to a function) and formal parameters (placeholders in the function definition).
Common runtime errors:
Division by zero as an example of a runtime error.
Do-while concept: Python has no do-while loop; the equivalent is a while loop with careful initial condition.
Syntax errors: common mistakes leading to syntax errors (e.g., mishandled punctuation, mismatched brackets).
The exam will include content on how to interpret and apply these concepts in small problems and tracing tasks.
Exercise 6 and bonus activity context (discussion in Q&A)
Exercise 6 scenario: a list of dictionaries with student records; checking for duplicates by course code.
Practical approach suggested:
Iterate through the list; for each dictionary (index), compare the input code with the dictionary's code field.
Case-insensitive comparison and whitespace handling matter for equality.
If a match is found, you can treat it as a duplicate; otherwise, add a new entry.
Case sensitivity and spaces:
Case-insensitive comparisons treat MMS1-4-1 the same regardless of capitalization, but spaces matter for semantic meaning (e.g., "washer" vs "wash er").
Interaction expectations for bonus activity:
The instructor emphasized that participation is not optional; but attendance is optional for Zoom sessions.
Positive engagement, response to classmates’ outputs, and respectful interactions are encouraged but not strictly mandated.
Final reminders and expectations for the trimester
Finals will reuse the same format as midterms: multiple-choice with short tracing tasks.
Three-day finals window is planned to accommodate different schedules.
Students are encouraged to seek help via video calls or consultations; no mandatory attendance, but access to instructor support remains available.
The instructor underscored a philosophy: modules and handouts should be sufficient for programming proficiency; external resources are discouraged to avoid off-topic complexity.
Quick takeaways for exam readiness
Be comfortable with:
Function definitions and parameter passing (formal vs actual).
Tracing outputs for loops and conditionals, including edge cases with modulo and ranges.
Understanding Python's control structures: there is no do-while loop; equivalent patterns rely on while with pre/post checks.
Basic file I/O patterns: opening with r/w/a, reading contents, and writing text with \n line separators; handling missing files.
Basic dictionary usage: key-value storage, dictionary access, and sorting by values to produce high-score lists.
Handling runtime errors with try/except, including type errors (non-integers), and value errors (out of range).
Summary of stimulation and direction
The session balanced practical implementation (project details) with conceptual understanding (exams, errors, and data storage).
Students are encouraged to think programmatically about multimedia contexts and to reflect their journey through comments and project design.
Glossary (key terms mentioned)
Error handling, try/except, FileNotFoundError
open, close, with, mode (r, w, a)
read(), readline(), readlines(), write(), append
dictionary, key, value, tuple as key, nested dictionaries
high scores, persistence, sorting by value
random, randint, range, iterations
local scope, formal parameters, actual parameters
do-while (not present in Python), break, continue
pseudocode, true vs false conditions, boolean operators (not, and, or)
MMS 144 (introduction to databases) and the progression from files to databases
Notable formulas and LaTeX representations
Secret number range:
Attempts example (game narrative):
Score dictionary concept (tuple key):
\text{score t family}\left( (\text{game ext_umber}, \text{Name}) \right) = \text{attempts}
Sorting high scores by attempts (ascending):
If you want to visualize a minimal example (conceptual)
Suppose you have two games:
Game 1: (1, "Alex") -> 3
Game 2: (2, "Maria") -> 5
A snippet to retrieve top scores might sort by the second element (attempts) and display the name and attempts.
Final note
The notes above consolidate the major and minor points discussed in the transcript, including project design, error handling, file I/O, exam structure, and practical tips for MMS 1-4-1.