Course of Raku / Advanced / Modules / Modules basics / Exercises
Use a stats module
Problem
You are given a module Stats.rakumod that exports two
subroutines — total and mean — where
mean is built on top of total:
unit module Stats;
sub total(@numbers) is export {
[+] @numbers
}
sub mean(@numbers) is export {
total(@numbers) / @numbers.elems
}Write a separate program that uses this module and, for the list
10, 20, 30, 40, prints both the total and the mean.
Example
Run with the module on the search path, the program prints:
$ raku -I. stats.raku
total: 100
mean: 25Solution
Course navigation
← Solution: Use the converter | Solution: Use a stats module →