OIM3640 - Problem Solving and Software Design

2026 Spring

Session 17 (3/26)

contain

Today's Agenda

  • Announcements/Updates
  • Quiz 2: Data Structures
  • Lecture: File I/O Essentials
  • MP2 Work Time

Announcements/Updates

  • Quiz 2 today!
  • Next class: Introduction to APIs and JSON
    • Register on OpenWeather and get a free API key before next class
    • Do not share your API key or post it on GitHub
  • Mini Project 2: Work on proposals and prototypes
  • Communication
    • Office Hours: Walk-in or by appointment
    • Email: Specify course # in subject, e.g., "OIM3640: GitHub settings"
    • You are required to meet with me at least once this semester
  • Questions?

📝 Quiz 2: Data Structures

Topics covered:

  • Lists, tuples, dicts, sets
  • Mutability, operations, methods
  • Choosing the right data structure
  • The counting pattern

Time: ~40 minutes

One cheat sheet allowed (one page, both sides).

File I/O: Reading Files

with open('jekyll.txt') as f:
    for line in f:            # line by line
        print(line.strip())

with open('jekyll.txt') as f:
    text = f.read()           # entire file as string

with closes the file automatically when done.

File I/O: Writing Files

with open('results.txt', 'w') as f:
    for word, count in top[:10]:
        f.write(f'{word}: {count}\n')

File modes: 'r' read (default), 'w' write, 'a' append

'w' creates a new file or overwrites an existing one!

📝 Your Turn: MP2 Work Time

  • Write your PROPOSAL.md if you haven't
  • Find a text source you're curious about
    • Books, lyrics, articles, your own writing, etc.
  • Try reading it with with open(...)
  • Count word frequencies, find patterns

Use only built-in Python first - no external libraries yet!

Before You Leave

  • Any questions?
  • Continue your Learning Log for this week (logs/wk09.md)
  • Work on MP2 (proposal + prototype)
  • Push your work to GitHub

Next session: APIs and JSON

global styles