JMU
Accumulators
A Programming Pattern (With Examples in Python)


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu


Motivation
Review
Review (cont.)

Getting Started

pythonexamples/programmingpatterns/accumulators/Accumulators.py (Fragment: loop)
        

What "needs to be done" at each iteration?

Thinking About the Problem
The Pattern
Types of Accumulators
A Numeric Example

Finding the Maximum

pythonexamples/programmingpatterns/accumulators/Accumulators.py (Fragment: max)
        
A Boolean Example

Containment

pythonexamples/programmingpatterns/accumulators/Accumulators.py (Fragment: contains)
        
Examples with Multiple Accumulators

The Mean After Dropping the Lowest Value

pythonexamples/programmingpatterns/accumulators/Accumulators.py (Fragment: droplowest)
        
An Example with a Common "Twist"

The Index of the Largest Element

pythonexamples/programmingpatterns/accumulators/Accumulators.py (Fragment: argmax)