Moodle CodeRunner
Free CodeRunner questions for Moodle
65 programming questions for Moodle's CodeRunner in Python, Java, C and C++, each with a sample answer and tests. Download the Moodle XML, import it into your question bank and add the questions to a quiz. Free under CC BY 4.0, with the question text in English, Portuguese or Spanish.
By the OnlineCompiler.io team. Updated .
Também em portuguêsTambién en español
What the packs are
Each pack is a Moodle XML file of CodeRunner questions for a first programming course. A question asks for a function, a method or a whole program, and CodeRunner grades the student's answer against the question's tests when they press Check. Every question has a sample answer that passes all its tests.
The questions use only CodeRunner's built-in question types (python3, java_method, java_class, java_program, c_function, c_program, cpp_function, cpp_program) and leave the sandbox settings to them, so they import into any Moodle with CodeRunner installed and run on any Jobe server: your own, your university's or OnlineCompiler.io's.
Each pack comes in English, Portuguese and Spanish. Only the question text changes; the code, the tests and the expected output are the same in all three, so you can give each class the language it reads best and grade them all the same way.
They are free under CC BY 4.0: use them, change them and share them, crediting OnlineCompiler.io.
The packs
65 questions and 363 tests in 4 packs, one for each programming language.
Python: first-year programming
Functions, conditions, loops, strings, lists, dictionaries and recursion, from first steps to the end of a first course.
- 20 questions, 111 tests (38 hidden)
- Question types:
python3 - Topics: Input and output, Conditions, Loops, Functions, Strings, Lists and arrays, Dictionaries and maps, Recursion, Searching and sorting
The 20 questions
| # | Question | Topic | Type | Tests |
|---|---|---|---|---|
| 1 | Sum and difference | Input and output | python3 | 4, 2 hidden |
| 2 | Seconds to H:MM:SS | Input and output | python3 | 5, 2 hidden |
| 3 | Distance between two points | Functions | python3 | 6, 2 hidden |
| 4 | Ticket price by age | Conditions | python3 | 6, 3 hidden |
| 5 | Leap year | Conditions | python3 | 5, 1 hidden |
| 6 | Quadrant of a point | Conditions | python3 | 6, 2 hidden |
| 7 | Multiplication table | Loops | python3 | 5, 2 hidden |
| 8 | Sum of the digits | Loops | python3 | 6, 2 hidden |
| 9 | Collatz steps | Loops | python3 | 5, 1 hidden |
| 10 | Counting primes | Functions | python3 | 6, 2 hidden |
| 11 | Count the vowels | Strings | python3 | 4, 1 hidden |
| 12 | Is it a palindrome? | Strings | python3 | 6, 2 hidden |
| 13 | Caesar cipher | Strings | python3 | 6, 2 hidden |
| 14 | Running total | Lists and arrays | python3 | 6, 2 hidden |
| 15 | Second largest value | Lists and arrays | python3 | 6, 2 hidden |
| 16 | Transpose a matrix | Lists and arrays | python3 | 6, 2 hidden |
| 17 | Counting words | Dictionaries and maps | python3 | 5, 2 hidden |
| 18 | Election winner | Dictionaries and maps | python3 | 6, 2 hidden |
| 19 | Sum of a nested list | Recursion | python3 | 6, 2 hidden |
| 20 | Binary search | Searching and sorting | python3 | 6, 2 hidden |
Java: first-year programming
Methods, conditions, loops, strings, arrays, classes and recursion, for a first course in Java.
- 15 questions, 84 tests (29 hidden)
- Question types:
java_method,java_class,java_program - Topics: Input and output, Conditions, Loops, Functions, Strings, Lists and arrays, Dictionaries and maps, Recursion, Classes and objects
The 15 questions
| # | Question | Topic | Type | Tests |
|---|---|---|---|---|
| 1 | Seconds to H:MM:SS | Input and output | java_program | 6, 2 hidden |
| 2 | Largest of three | Conditions | java_method | 4, 1 hidden |
| 3 | Leap year | Conditions | java_method | 6, 2 hidden |
| 4 | Sum of n numbers | Loops | java_program | 4, 2 hidden |
| 5 | Staircase of stars | Loops | java_method | 5, 2 hidden |
| 6 | Temperature conversion | Functions | java_method | 6, 2 hidden |
| 7 | GCD and LCM | Functions | java_method | 6, 2 hidden |
| 8 | Initials of a name | Strings | java_method | 6, 2 hidden |
| 9 | Palindrome check | Strings | java_method | 6, 2 hidden |
| 10 | Position of the largest | Lists and arrays | java_method | 6, 2 hidden |
| 11 | Above the average | Lists and arrays | java_program | 6, 2 hidden |
| 12 | Most frequent word | Dictionaries and maps | java_method | 6, 2 hidden |
| 13 | Bank account | Classes and objects | java_class | 6, 2 hidden |
| 14 | Fractions | Classes and objects | java_class | 6, 2 hidden |
| 15 | Towers of Hanoi | Recursion | java_method | 5, 2 hidden |
C: first-year programming
Input and output, conditions, loops, functions, arrays, strings, pointers and structs, for a first course in C.
- 15 questions, 85 tests (29 hidden)
- Question types:
c_function,c_program - Topics: Input and output, Conditions, Loops, Functions, Strings, Lists and arrays, Pointers and memory, Structs
The 15 questions
| # | Question | Topic | Type | Tests |
|---|---|---|---|---|
| 1 | Celsius to Fahrenheit | Input and output | c_program | 6, 2 hidden |
| 2 | Format a duration | Input and output | c_function | 6, 2 hidden |
| 3 | Leap year | Conditions | c_function | 6, 2 hidden |
| 4 | Quadrant of a point | Conditions | c_function | 6, 2 hidden |
| 5 | Count even and odd numbers | Loops | c_program | 4, 2 hidden |
| 6 | Floyd's triangle | Loops | c_function | 5, 2 hidden |
| 7 | Factorial | Functions | c_function | 4, 1 hidden |
| 8 | Prime number check | Functions | c_function | 6, 2 hidden |
| 9 | Reverse an array | Lists and arrays | c_function | 6, 2 hidden |
| 10 | Above the average | Lists and arrays | c_program | 6, 2 hidden |
| 11 | Palindrome check | Strings | c_function | 6, 2 hidden |
| 12 | Caesar cipher | Strings | c_function | 6, 2 hidden |
| 13 | Minimum and maximum | Pointers and memory | c_function | 6, 2 hidden |
| 14 | Repeat a string | Pointers and memory | c_function | 6, 2 hidden |
| 15 | Adding fractions | Structs | c_function | 6, 2 hidden |
C++: first-year programming
Functions, conditions, loops, strings, vectors, maps, classes and recursion, for a first course in C++.
- 15 questions, 83 tests (29 hidden)
- Question types:
cpp_function,cpp_program - Topics: Input and output, Conditions, Loops, Functions, Strings, Lists and arrays, Dictionaries and maps, Recursion, Classes and objects
The 15 questions
| # | Question | Topic | Type | Tests |
|---|---|---|---|---|
| 1 | Rectangle area and perimeter | Input and output | cpp_program | 5, 2 hidden |
| 2 | Days in a month | Conditions | cpp_function | 6, 2 hidden |
| 3 | Kind of triangle | Conditions | cpp_function | 6, 2 hidden |
| 4 | Collatz steps | Loops | cpp_function | 6, 2 hidden |
| 5 | Largest and smallest | Loops | cpp_program | 5, 2 hidden |
| 6 | Sort three variables | Functions | cpp_function | 6, 2 hidden |
| 7 | Overloaded area | Functions | cpp_function | 6, 2 hidden |
| 8 | Tower of Hanoi | Recursion | cpp_function | 5, 2 hidden |
| 9 | Reverse the words | Strings | cpp_program | 4, 2 hidden |
| 10 | Compress repeated letters | Strings | cpp_function | 6, 2 hidden |
| 11 | Average of a vector | Lists and arrays | cpp_function | 4, 1 hidden |
| 12 | Remove duplicates | Lists and arrays | cpp_function | 6, 2 hidden |
| 13 | Word frequencies | Dictionaries and maps | cpp_function | 6, 2 hidden |
| 14 | Bank account class | Classes and objects | cpp_function | 6, 2 hidden |
| 15 | Clock class | Classes and objects | cpp_function | 6, 2 hidden |
Import a pack into Moodle
Importing needs editing rights in the course, and CodeRunner installed on the site. Moodle 5.0 moved question banks out of courses and into question bank activities, so the steps depend on your version.
Moodle 4.x
- Download the pack in the language you want, from the list above.
- In your course, open More > Question bank.
- In the menu at the top left of the page, which shows Questions, choose Import.
- Under File format, choose Moodle XML format.
- Under General, leave Get category from file and Get context from file ticked.
- Drop the file into Import questions from file and press Import. Moodle lists the questions it imported; press Continue.
The questions land in the course's question bank, in a new category named after the pack and its language, such as OnlineCompiler.io Python (English).
Moodle 5.0 and later
- In your course, open More > Question banks. Open a bank, or make one: press Add question bank, give it a name and choose Save and display.
- In the bank, choose Import from the menu at the top left, which shows Questions.
- Under File format, choose Moodle XML format, drop the file into Import questions from file, press Import and then Continue.
The questions go into the bank you imported into, in a category such as OnlineCompiler.io Python (English). In Moodle 5.0 every quiz also has a question bank of its own (in the quiz, Question bank) for questions only that quiz uses; importing there works the same way.
Add the questions to a quiz
- Open the quiz and go to its Questions page.
- Choose Add, then from question bank. In Moodle 5.0 and later, if the bank you imported into isn't the one shown, choose Switch bank and pick it.
- Pick the pack's category, tick the questions you want and press Add selected questions to the quiz.
Each question is worth one mark and earns it only when every test passes. Change a question's mark on the quiz's Questions page, or edit the question to change anything else.
Moodle's own guides: Import questions (Moodle 4.5) and Question banks (Moodle 5.0).
Run them without your own Jobe server
CodeRunner runs every Check on a Jobe server. If your Moodle already has one, the questions work as they are. If it doesn't, or it still uses the default server meant only for testing, OnlineCompiler.io's Jobe-compatible server can run them, in one of two ways.
For the whole site: two settings
A Moodle administrator opens Site administration > Plugins > Question types > CodeRunner, sets Jobe server to https://api.onlinecompiler.io/api and sets Jobe API key to an OnlineCompiler.io API key. Every CodeRunner question on the site, these packs included, then runs on OnlineCompiler.io. CodeRunner without a Jobe server has the steps, the limits and what differs from Jobe.
For these questions only: a copy with your API key
If you teach without access to the site settings, download a copy of a pack whose questions carry the server and your API key in their own sandbox parameters. CodeRunner sends just those questions to OnlineCompiler.io; every other question on the site keeps using the site's Jobe server. Each question's Parameters field gets:
{"jobeserver": "https://api.onlinecompiler.io/api", "jobeapikey": "YOUR_API_KEY"}In the C and C++ packs it also has "linkargs": ["-lm"]: the C and C++ question types set it to link the maths library, and a question's own parameters replace its question type's.
Your key stays in this browser tab. The page downloads the pack, writes the key into each question and saves the copy on your computer; the key isn't sent anywhere, put in a link or stored.
Anyone who can edit these questions in Moodle can read the key, in the question's Parameters field (under Advanced customisation, in the Sandbox group), and so can anyone with an export or a backup of them. Students don't see it. Use a separate API key for each course, with its own monthly limit, so a key that gets out can only spend that course's runs and can be deleted without touching your other courses: see per-key limits.
A Check runs the student's code once for most questions that ask for a function or a method, and once per test for questions that ask for a whole program or read input. Each run counts toward your plan; the free plan includes 100,000 runs a month.
To send the questions back to the site's Jobe server, clear their Parameters field, or import the plain file instead.
Licence
The questions, their tests and their sample answers are licensed under Creative Commons Attribution 4.0 (CC BY 4.0). You may copy, change and share them, in your courses or anywhere else, as long as you credit OnlineCompiler.io and say if you changed them. For example:
Based on CodeRunner questions by OnlineCompiler.io (https://onlinecompiler.io/coderunner-question-packs), CC BY 4.0.
Each file's category description already says where the questions come from.
Frequently asked questions
Where can I find free CodeRunner questions?
On this page: 65 free CodeRunner questions in Python, Java, C and C++, as Moodle XML files you import into your question bank. Each has a sample answer and tests, the question text comes in English, Portuguese or Spanish, and they are licensed under CC BY 4.0.
Do these questions need a Jobe server?
Yes, like every CodeRunner question: the Jobe server is what runs the students' code. Any Jobe server works, because the questions use only CodeRunner's built-in question types. Without one of your own, use OnlineCompiler.io's Jobe-compatible server (https://api.onlinecompiler.io/api), for the whole site or, with the key download on this page, for these questions only.
Which versions of Moodle and CodeRunner do they work with?
Any Moodle with CodeRunner installed, because the questions use only CodeRunner's built-in question types and the standard Moodle XML format. Current CodeRunner releases (5.x) need Moodle 4.3 or later, and this page has the import steps for Moodle 4.x and for Moodle 5.0 and later. A question carrying its own Jobe server and key was tested on Moodle 4.5 with CodeRunner 5.10.9.
Can I edit the questions?
Yes. Once imported they are ordinary CodeRunner questions in your question bank: change the text, the tests, the marks or the sample answer. The CC BY 4.0 licence lets you share your changed versions too, crediting OnlineCompiler.io.
Are the questions available in Portuguese or Spanish?
Yes. Every pack comes in English, Brazilian Portuguese and Spanish, with the same code and tests in each; only the question text changes.
How are the questions checked?
Every sample answer passes all of its question's tests on a stock Jobe server and on OnlineCompiler.io. We check this by running each one through the same templates CodeRunner's built-in question types use, on both servers, and by importing every pack file into Moodle 4.5 with CodeRunner 5.10 and grading each question's sample answer there.
How do students get feedback?
Through the Check button: students run their code against the tests and see a table with the expected and actual output of each visible test. One or more tests show in the question as examples, and hidden tests aren't shown, so nobody can write an answer that only fits the examples; if one fails, CodeRunner only says a hidden test failed. Students can fix their code and press Check again, losing a little of the mark for each wrong try.