Indicator Functions
A Programming Pattern (With Examples in Python)
Prof. David Bernstein
James Madison University
Computer Science Department
bernstdh@jmu.edu
Motivation
The Idea:
Problems in which an
indicator’s
value must be
calculated before it can be used in another expression
An Example:
"The show must go on" (i.e., the number of seats sold
for a particular show time must be used to calculate an
indicator, setting it to 0 when no tickets have been sold
and setting it to 1 otherwise)
Review
A Specific Solution that Leads to Code Duplication: