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
#QuestionTopicTypeTests
1Sum and differenceInput and outputpython34, 2 hidden
2Seconds to H:MM:SSInput and outputpython35, 2 hidden
3Distance between two pointsFunctionspython36, 2 hidden
4Ticket price by ageConditionspython36, 3 hidden
5Leap yearConditionspython35, 1 hidden
6Quadrant of a pointConditionspython36, 2 hidden
7Multiplication tableLoopspython35, 2 hidden
8Sum of the digitsLoopspython36, 2 hidden
9Collatz stepsLoopspython35, 1 hidden
10Counting primesFunctionspython36, 2 hidden
11Count the vowelsStringspython34, 1 hidden
12Is it a palindrome?Stringspython36, 2 hidden
13Caesar cipherStringspython36, 2 hidden
14Running totalLists and arrayspython36, 2 hidden
15Second largest valueLists and arrayspython36, 2 hidden
16Transpose a matrixLists and arrayspython36, 2 hidden
17Counting wordsDictionaries and mapspython35, 2 hidden
18Election winnerDictionaries and mapspython36, 2 hidden
19Sum of a nested listRecursionpython36, 2 hidden
20Binary searchSearching and sortingpython36, 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
#QuestionTopicTypeTests
1Seconds to H:MM:SSInput and outputjava_program6, 2 hidden
2Largest of threeConditionsjava_method4, 1 hidden
3Leap yearConditionsjava_method6, 2 hidden
4Sum of n numbersLoopsjava_program4, 2 hidden
5Staircase of starsLoopsjava_method5, 2 hidden
6Temperature conversionFunctionsjava_method6, 2 hidden
7GCD and LCMFunctionsjava_method6, 2 hidden
8Initials of a nameStringsjava_method6, 2 hidden
9Palindrome checkStringsjava_method6, 2 hidden
10Position of the largestLists and arraysjava_method6, 2 hidden
11Above the averageLists and arraysjava_program6, 2 hidden
12Most frequent wordDictionaries and mapsjava_method6, 2 hidden
13Bank accountClasses and objectsjava_class6, 2 hidden
14FractionsClasses and objectsjava_class6, 2 hidden
15Towers of HanoiRecursionjava_method5, 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
#QuestionTopicTypeTests
1Celsius to FahrenheitInput and outputc_program6, 2 hidden
2Format a durationInput and outputc_function6, 2 hidden
3Leap yearConditionsc_function6, 2 hidden
4Quadrant of a pointConditionsc_function6, 2 hidden
5Count even and odd numbersLoopsc_program4, 2 hidden
6Floyd's triangleLoopsc_function5, 2 hidden
7FactorialFunctionsc_function4, 1 hidden
8Prime number checkFunctionsc_function6, 2 hidden
9Reverse an arrayLists and arraysc_function6, 2 hidden
10Above the averageLists and arraysc_program6, 2 hidden
11Palindrome checkStringsc_function6, 2 hidden
12Caesar cipherStringsc_function6, 2 hidden
13Minimum and maximumPointers and memoryc_function6, 2 hidden
14Repeat a stringPointers and memoryc_function6, 2 hidden
15Adding fractionsStructsc_function6, 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
#QuestionTopicTypeTests
1Rectangle area and perimeterInput and outputcpp_program5, 2 hidden
2Days in a monthConditionscpp_function6, 2 hidden
3Kind of triangleConditionscpp_function6, 2 hidden
4Collatz stepsLoopscpp_function6, 2 hidden
5Largest and smallestLoopscpp_program5, 2 hidden
6Sort three variablesFunctionscpp_function6, 2 hidden
7Overloaded areaFunctionscpp_function6, 2 hidden
8Tower of HanoiRecursioncpp_function5, 2 hidden
9Reverse the wordsStringscpp_program4, 2 hidden
10Compress repeated lettersStringscpp_function6, 2 hidden
11Average of a vectorLists and arrayscpp_function4, 1 hidden
12Remove duplicatesLists and arrayscpp_function6, 2 hidden
13Word frequenciesDictionaries and mapscpp_function6, 2 hidden
14Bank account classClasses and objectscpp_function6, 2 hidden
15Clock classClasses and objectscpp_function6, 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

  1. Download the pack in the language you want, from the list above.
  2. In your course, open More > Question bank.
  3. In the menu at the top left of the page, which shows Questions, choose Import.
  4. Under File format, choose Moodle XML format.
  5. Under General, leave Get category from file and Get context from file ticked.
  6. 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

  1. 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.
  2. In the bank, choose Import from the menu at the top left, which shows Questions.
  3. 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

  1. Open the quiz and go to its Questions page.
  2. 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.
  3. 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:

Parameters
{"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.

Make one on the API keys page of your dashboard, ideally a new key for this course.

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.