OIM3640 - Problem Solving and Software Design

2026 Spring

Session 08 (2/12)

contain

Today's Agenda

Announcements/Updates

  • Repo Structure — follow naming conventions:
    • notebooks/ — Jupyter notebooks
    • logs/ — Learning logs: s01.md, wk04.md, ideas.md, ...
    • code/ — Chapter exercises: ch01_ex02.py, ch03_ex01.py, ...
    • Write meaningful commit messages (not "update" or "fix")
  • Getting Help
    • Office Hours: By appointment (in-person preferred or Webex)
    • Meet with me in person at least once this semester
    • Email: Specify course # in subject, e.g., "OIM3640: GitHub settings"
  • Questions?

Mini Projects Preview

This semester: 3 required + 1–2 elective mini projects (4–5 total)

# Project Core Skills
1 Your First Python App Functions, logic, user interaction
2 Text Analysis Strings, files, dicts
3 Web App Flask, HTML, APIs

You can start Project 1 now! Build a Python program that takes user input, processes it, and produces meaningful output.

  • Submit PROPOSAL.md first, then code iteratively
  • Goal: finish each project in 2-3 weeks, with checkpoints to track your progress

Quick Quiz - Python Trivia Facts

  1. Where does the name "Python" for the programming language come from?
    1. Guido van Rossum's favorite pet animal
    2. Guido van Rossum's favorite comedy TV show
    3. Guido van Rossum's favorite artwork
    4. Guido van Rossum's favorite mythical creature
  2. Is Python open source? Can anyone contribute to it?

One More Python Programming Fun Fact

  • Try 0.1 + 0.2 in Python interactive shell
    • Do not worry! It is NORMAL!
    • This happens in all programming languages that use floating point decimals, not just in Python.
    • Because computers represent decimal numbers in binary (Base-2) format.
    • Check out https://0.30000000000000004.com
  • How to avoid?

What We've Learned So Far

  • Variables & Types: int, float, str, bool, NoneType
  • Operators: +, -, *, /, //, %, **
  • Functions:
    • def, parameters, arguments
    • return vs print()critical distinction!
    • Scope: local vs global variables
    • Docstrings and naming (verb_noun)
  • for loop: for i in range(n):
  • Turtle: Drawing shapes with loops and functions
    • Try python -m turtledemo in Command Prompt/Terminal

More on Functions

Why do functions matter beyond just organizing code?

Two big ideas:

  • Decomposition: Break big problems into smaller, manageable pieces
  • Abstraction: Hide the details, focus on inputs and outputs

Chapter 6 - Return Values

What we'll learn:

  • Functions that return values (deeper dive)
  • Incremental development
  • Boolean functions
  • Composition of functions

Return Values: A Deeper Look

We've seen return before. Now let's explore further:

import math

def area(radius):
    """Calculate the area of a circle."""
    return math.pi * radius ** 2

The return value can be:

  • Used in expressions: total = area(5) + area(3)
  • Passed to other functions: print(area(5))
  • Stored in variables: a = area(5)

Incremental Development

Don't write the whole function at once! Fake it till you make it!

Example: distance between two points and

Step 1: Start with a skeleton

def distance(x1, y1, x2, y2):
    return 0.0  # placeholder — fake it till you make it!

Incremental Development (continued)

Step 2: Add intermediate calculations

def distance(x1, y1, x2, y2):
    dx = x2 - x1
    dy = y2 - y1
    print(f"dx = {dx}, dy = {dy}")  # temporary
    return 0.0

Step 3: Complete the function

def distance(x1, y1, x2, y2):
    dx = x2 - x1
    dy = y2 - y1
    return (dx**2 + dy**2) ** 0.5

Build up one piece at a time. Test at each step.

Composing Functions

Functions can call other functions:

def circle_area(radius):
    import math
    return math.pi * radius ** 2

def ring_area(outer, inner):
    """Area of a ring (donut shape)."""
    return circle_area(outer) - circle_area(inner)
ring_area(5, 3)  # area between radius 5 and radius 3

This is the power of decomposition!

Boolean Functions

Functions that return True or False:

def is_even(n):
    """Check if n is an even number."""
    return n % 2 == 0
is_even(4)   # True
is_even(7)   # False

Naming convention: start with is_ or has_

We'll use these with conditionals next!

Chapter 5 - Conditionals

What we'll learn:

  • Boolean expressions and comparison operators
  • Logical operators (and, or, not)
  • Conditional statements (if/elif/else)
  • Nested conditionals
  • Recursion (optional)

Boolean Expressions

Expressions that evaluate to True or False:

x = 5
x == 5     # True   (equality)
x != 3     # True   (not equal)
x > 10     # False  (greater than)
x >= 5     # True   (greater than or equal)

Logical operators combine conditions:

age = 25
age >= 18 and age < 65   # True
age < 18 or age >= 65    # False
not (age < 18)           # True

Conditional Statements

if score >= 90:
    print("A")
elif score >= 80:
    print("B")
elif score >= 70:
    print("C")
else:
    print("F")

Key points:

  • Order matters - first matching condition wins
  • elif and else are optional
  • Each branch must be indented

Nested Conditionals

if x == y:
    print("x and y are equal")
else:
    if x < y:
        print("x is less than y")
    else:
        print("x is greater than y")

Can often be simplified with elif:

if x == y:
    print("x and y are equal")
elif x < y:
    print("x is less than y")
else:
    print("x is greater than y")

Recursion (Optional)

A function that calls itself:

def countdown(n):
    if n <= 0:
        print("Go!")
    else:
        print(n)
        countdown(n - 1)
countdown(3)  # prints: 3, 2, 1, Go!
  • Every recursive function needs a base case (when to stop)
  • Recursion is powerful but can be tricky for beginners
  • This topic is optional - focus on conditionals first

📝 Your Turn

Open Chapter 6 and Chapter 5 notebooks

Work through the examples and exercises:

  • Chapter 6: Return values, incremental development, composition
  • Chapter 5: Boolean expressions, conditionals (if/elif/else)
  • Recursion exercises are optional

Questions? Ask now!

Before You Leave (5 min)

  • Any questions so far?
  • Continue your Learning Log for this week (logs/wk04.md)
  • Work on Chapter 6 and Chapter 5 exercises
    • Recursion exercises are optional
  • Start thinking about Mini Project 1 ideas
  • Push your work to GitHub

Next session: Iteration and Search (Chapter 7)

global styles