Otter
Snippets
Otter
Upstream Otter 1.0.1 Tested
Calculate List Average
Compute the arithmetic mean of all numeric elements in a list.
Architecture & Runtime Preview
Otter 1.0.1Zero-dependency Otter 1.0.1 snippet (Math & Numbers). Copy the parameterized template or run the self-contained example.
- 1Category: Math & Numbers
- 2Attribution: Otter Reusable Library (Official)
- 3Zero external pack dependencies — paste directly into any .ot file
Source Code (2 files)
to calcAverage items
total is 0
count is 0
for each item in items
total is total plus item
increase count by 1
.
if count is 0
return 0
.
return total divided by count
.
to calcAverage items
total is 0
itemCount is 0
for each item in items
total is total plus item
increase itemCount by 1
.
if itemCount is 0
return 0
.
return total divided by itemCount
.
grades are
85
90
95
.
avg is calcAverage grades
say "Class average:" avg
if avg is not 90
fail with "calcAverage mismatch: expected 90"
.
Installation & Usage
otter snippet inspect math-calc-average
Copy template.ot directly into your .ot source file, or run example.ot with 'otter run example.ot'.