Course of Raku / Essentials / The MAIN function / Exercises

Perimeter of a rectangle

Problem

Write a program that computes and prints the perimeter of a rectangle. Pass the lengths of two sides in command-line arguments. If it is a square, pass a single value. Use the MAIN function.

Example

The program should explicitly confirm if it works with a square or a rectangle. Here is a possible output for the two cases:

$ raku perimeter.raku 15
The perimeter of a square is 60.

$ raku perimeter.raku 15 20
The perimeter of a rectangle is 70.

Solution

See the solution

Course navigation

Built-in functions for printing / note   |