W WolfCode · CSC 141

Multi-args Averaging

三参数求平均

≈ 20 min · python-functions · Open in WolfCode

Two functions. One calls the other. Smallest example of composition (Think Python §3.4) — and the DRY principle (§3.11).

The two functions

Python · runnable

Why composition matters

From Think Python §3.11: "Functions can make a program smaller by eliminating repetitive code. Later, if you make a change, you only have to make it in one place."

Float vs int

Python · runnable