Small exercises
Build short programs using only ideas from the Learn lessons. Hints are below each task; solutions are collapsed.
Exercise A — Two lines
Print your name, then print the number 1.
Hint
Use two say instructions. Numbers do not need quotes. Text does.
One solution
echo
say("Ada");
say(1);Exercise B — Age check
Store an age in a variable. If it is at least 18, print Adult. Otherwise print Young.
Hint
Lesson 3: if / else, type int.
One solution
echo
age: int = 20;
if age >= 18 {
say("Adult");
} else {
say("Young");
}Exercise C — Countdown
Print 3, then 2, then 1 using a while loop.
Hint
Start at 3. While the number is at least 1, print it, then subtract 1.
One solution
echo
n: int = 3;
while n >= 1 {
say(n);
n = n - 1;
}Exercise D — Greeter function
Write a function greet that takes a str name and prints Hello, followed by that name. Call it with "Echo".
Hint
Lesson 5: fn greet(name: str) { ... } then greet("Echo");.
One solution
echo
fn greet(name: str) {
say("Hello,", name);
}
greet("Echo");Exercise E — First list item
Create a list of three numbers. Print only the first item, then print the whole list after pushing 99.
One solution
echo
nums: list = [10, 20, 30];
say(nums[0]);
nums.push(99);
say(nums);