Program listings can be more that just live demonstrations, they can be exercises. The first two also occur in the sample article where they just get a static rendering, if at all.
An exercise might ask a reader to write a computer program, that would go here in the <statement>. But you can also add a <program> element after a <statement>. Here we place no code at all, but we do say we want it to be interactive. The purpose is to make it a live coding environment for a version of your output that allows the reader to perhaps submit a solution. The <program> element is necessary so you can specify a programming language.
Similar to above, but now as a complete Python program inside an <activity>. This demonstrates the possibility to use any βproject-likeβ block (<project>, <activity>, <exploration>, <investigation>), but not in the case when structured with <task>. (There is an empty <tests> element here, designed to test relief for an error this will cause on a Runestone server.)
Checkpoint5.4.4.An Exercise with a Static Program.
Similar to above, again, but we place the <program> element inside the <statement>, not after it as a peer. This signals that this is not a coding exercise and the program will render static, since it is explicitly labeled as not being interactive.
An activecode exercise can offer extra help to a reader who gets stuck, via Runestoneβs CodeTailor feature. A @codetailor attribute adds a βGet Helpβ button that, on a Runestone server, presents a personalized Parsons problemβthe blocks of a correct solution, scrambled for the reader to reassemble, where a block may hold one line of code or several. The value all scrambles a complete solution, while incorrect locks the blocks a reader already has right, so only the wrong ones move. A companion @codetailor-fallback names, by its @xml:id, a Parsons problem elsewhere in this document to present when a personalized problem cannot be generated; without it, generation is always requested. The first exercise below elects all and falls back to a Parsons problem from a later chapter; the second elects incorrect and relies on generation alone.
Checkpoint5.4.6.Coding Exercise, with CodeTailor Help.
Write a function total that returns the sum of a list of numbers. If you get stuck, use the βGet Helpβ button to assemble a solution from scrambled blocks.
Checkpoint5.4.7.Coding Exercise, CodeTailor Help for Incorrect Blocks.
Write a function largest that returns the greatest number in a nonempty list. Here the βGet Helpβ button locks the blocks you already have right, so you rearrange only the incorrect ones.
public class Test1
{
public static void main(String[] args)
{
boolean isRaining = true;
if (isRaining)
{
System.out.println("Take an umbrella!");
}
System.out.println("Drive carefully");
}
}
In an interactive environment, the tests in this exercise will be made visible, but uneditable, so that in the event of a failed test the student can see exactly what is being tested (Doctest does not report on individual passed tests and the feedback on failed tests generally wonβt make sense without the test itself).
For simple programs, or languages without an available unit testing framework, input-output testing can be done instead. IO testing can only be done on languages that are run on a Runestone server (Java/C/C++/Octave/Python3).