How to make coding quiz in Moodle

Interest in coding is growing. In coding, a quiz is a very useful activity in checking the learner’s coding capability. If you install the CodeRunner plugin in Moodle quiz, it is possible to create a quiz that tests student’s code by running the code in a sandbox just like unit tests. Install and use the CodeRunner plugin.

More inforamtion is available as follows…

As shown in the figure above, CodeRunner uses Twig, the template language. After the program template is created, the learner ‘s code and the evaluator’ s precompiled code are combined and the template is completed. The template is made into an executable file. The input is entered and the result is compared with the result of the desired result. is. The following video is a description of my CodeRunner quizzes and how to use them. It is Korean but you can auto translate the caption to English 🙂

Some more information about how I used Twig for coding quiz.


import java.util.Scanner;
public class Main {
void aaa(){
{% set cond1= STUDENT_ANSWER|split('nextInt')|length %}
{% set cond2= STUDENT_ANSWER|split('print')|length %}
{% if (cond1 >= 2) and (cond2>=2) %}
Scanner sc=new Scanner({{TEST.stdin}});
{{STUDENT_ANSWER}}
{% else %}
System.out.println("while or break is not used"+{{cond1}}+{{cond2}});
{% endif %}
}

public static void main(String[] args) {
Main main = new Main();
main.runTests();
}

public void runTests() {
aaa();
}
}

public class Main {
void aaa(){
int a={{TEST.stdin}};
{% set cond1= STUDENT_ANSWER|split('while')|length %}
{% set cond2= STUDENT_ANSWER|split('break')|length %}
{% if (cond1 >= 2) and (cond2==2) %}
{{STUDENT_ANSWER}}
{% else %}
System.out.println("while or break is not used"+{{cond1}}+{{cond2}});
{% endif %}
}

public static void main(String[] args) {
Main main = new Main();
main.runTests();
}

public void runTests() {
aaa();
}
}

For Twig, I used

STUDENT_ANSWER|split(‘break’)|length 

to check the stirng “break” is included in stuent’s answer. If it is included once, it returns 2. Somehow ‘break’ is not well recognized and “break” worked better.

STUDENT_ANSWER|split(“break)|length

Also for the guide string I used

System.out.println(“Something is wrong”);

but the looks causing trouble and I changed it to

String aaa=”Something is wrong”;

System.out.println(aaa);

No problems for now.

Leave a Reply

Your email address will not be published. Required fields are marked *