Course of Raku / Essentials / Functions essentials / Built-in functions for printing / Exercises / Print the warning
Solution: Print the warning
Code
Here is the solution:
my $age = prompt 'What is your age? ';
if $age < 0 {
note 'You entered a negative number!';
}
else {
say "Your age is $age";
}🦋 Find the program in the file print-the-warning.raku.
Output
A couple of possible cases:
$ raku exercises/built-in-functions-for-printing/print-the-warning.raku
What is your age? 20
Your age is 20
$ raku exercises/built-in-functions-for-printing/print-the-warning.raku
What is your age? -1
You entered a negative number!To make sure the error message is printed to STDERR,
redirect the output. The prompt to enter the age will not appear, but
you can still enter a number. The warning remains visible.
$ raku exercises/built-in-functions-for-printing/print-the-warning.raku > /dev/null
20
$ raku exercises/built-in-functions-for-printing/print-the-warning.raku > /dev/null
-1
You entered a negative number!Course navigation
← Print
the warning | The
MAIN function →
Translations of this page: English • Deutsch • Español • Italiano • Latviešu • Nederlands • Български • Русский • Українська