Course of Raku / Advanced / Subroutines / Signatures / Exercises
An optional exponent
Problem
Write a subroutine power with a required parameter
$base and an optional parameter
$exp. When the exponent is given, raise the base to it;
when it is omitted, default to squaring (use the defined-or operator
// to supply 2).
Call it once with just a base, and once with a base and an exponent.
Example
The program prints:
25
125Solution
Course navigation
← Solution: Sum all arguments | Solution: An optional exponent →