Know some Python? Write your own interactive tutorial, with runnable examples and exercises, and share it with a link. Write and share your own tutorial.

Start writing

Learn Python / Create a quiz

How to Create a Python Quiz

Create a quiz

Anyone can build an interactive Python quiz here, using the same 11 question types as the quizzes at the end of our lessons. You fill in a form for each question, try it in the live preview, and publish it to get a link you can share.

How it works

  1. Open Create a quiz. Questions are listed on the left, the editor is in the middle and a live preview is on the right.
  2. Give the quiz a title, and optionally a description.
  3. Press Add a question and pick a type. Fill in the form; the preview updates as you type, and you can answer the question there to test it.
  4. Press Validate on a question to check it. It runs the same checks as publishing, so you can fix problems as you go.
  5. Press Publish. You get two links:
    • the public link to share with anyone;
    • a private edit link. It's the only way to change your quiz later, so save it somewhere safe. There are no accounts, so we can't send it to you again.

While you create a quiz, your draft is saved in your browser, so closing the tab doesn't lose it. Import / export shows the whole quiz as JSON: copy it to keep a backup, or paste one back in.

Questions per attempt picks that many questions at random each time someone takes the quiz, so a pool of 30 questions with 10 per attempt gives a different quiz each time. Leave it blank to ask every question.

Lists in the form: one per line

Several boxes take a list: accepted answers, wrong words for a word bank, group items, lines of code to arrange. In all of them:

  • Put each item on its own line. Press Enter after each one.
  • Commas are not separators. apple, pear on one line is a single item called "apple, pear". This is on purpose, because items like sum(a, b) contain commas.
  • Empty lines are ignored, so a blank line at the end does no harm.

For example, a group with three items is typed like this:

nums.sort()
nums.reverse()
nums.append(5)

The one exception is Fill in the blanks: each gap has its own one-line box, and you separate alternative answers with a vertical bar |, like sort | sort().

Writing good questions

  • One idea per question. If a question tests two things, a wrong answer doesn't tell the learner which one they missed.
  • Make the wrong answers believable. The best wrong choices are real beginner mistakes: an off-by-one index, sort() versus sorted(), = versus ==, forgetting that input() returns a string. A choice nobody would pick is wasted.
  • Keep code short. About 12 lines at most, so it fits without scrolling.
  • Always write an explanation. It's shown after every answer, right or wrong. Say why the answer is right, in a sentence or two. This is where people actually learn.
  • No trick questions, and avoid "all of the above".
  • Set a difficulty if you like (easy, medium, hard). The player shows easier questions first.

Formatting text

Questions, choices and explanations understand a small part of Markdown:

You write You get
`len(x)` (backticks) len(x)
**bold** bold
*italic* italic
A blank line A new paragraph

Links and HTML aren't allowed (HTML shows as plain text). Items that are dragged around (word-bank chips, match partners, group items) are plain text: to show one in a code font, wrap the whole item in backticks, like `sorted(x)`. The backticks aren't shown to the learner.

Multiple choice

The learner picks one answer from 2 to 6 choices. Use it to check a fact, a rule, or what a short snippet does.

In the builder:

  1. Question: what to answer. For example: What does `len([3, 1, 4])` return?
  2. Code snippet (optional): code shown above the choices. Leave it empty if the question doesn't need it.
  3. Choices: each choice has its own box. Type one answer per box, and click the round button to the left of the right one. Use Add a choice for more boxes (up to 6) and Γ— to remove one (at least 2 stay).
  4. Shuffle the choices (on by default): the order is mixed for every learner. Turn it off when the order means something, such as numbers in order.

Example:

Choice box Right?
2
3 ●
4
[3, 1, 4]

Common mistakes:

  • Forgetting to click the round button: the first choice is marked right until you change it.
  • Two choices that say the same thing. Every choice must be different.
  • A right answer that is obviously longer or more detailed than the others.

Select all that apply

Like multiple choice, but several choices are right. The learner must tick exactly the right ones (no more, no fewer) to get it correct.

In the builder:

  1. Question: for example, Which of these change the list `nums` itself?
  2. Choices: 3 to 7 boxes, one answer each. Tick the square box next to every right choice. At least one must be ticked, and not all of them.
  3. Shuffle the choices: as for multiple choice.

Example:

Choice box Right?
nums.append(4) β˜‘
nums.sort() β˜‘
sorted(nums)
nums + [4]

Tips: two or three right answers out of four or five works best. The page already tells the learner to select all the right answers, so you don't need to say it in the question.

True or false

The learner judges one statement. Quick, and good for common misconceptions.

In the builder:

  1. Question: write the statement itself, not a question. For example: `sorted(nums)` changes the order of the items in `nums`.
  2. Code snippet (optional): code the statement is about.
  3. The statement is: choose True or False.

Common mistakes: writing "Is it true that…?". Write the statement plainly. Also avoid "always" and "never" unless that is exactly the point.

Predict the output

The learner reads code and types exactly what it prints. This tests whether they can follow code in their head, which is the core skill of programming.

In the builder:

  1. Question: usually just "What does this print?".
  2. Code: the program. Indent with spaces; the Tab key inserts 4 spaces.
  3. What it prints: exactly what Python would show, one printed line per line. If the code calls print() three times, this box has three lines.
  4. Spacing must match exactly (off by default): when off, [1,2,3] is accepted for [1, 2, 3] and "a" for 'a', and the learner sees Python's exact output in a friendly note. Turn it on only when the spacing is what you're testing, such as sep=, end= or format widths.

Example:

Code box:

nums = [1, 2, 3]
alias = nums
alias.append(4)
print(nums)
print(len(nums))

What it prints box (two lines):

[1, 2, 3, 4]
4

Common mistakes:

  • Putting two printed lines on one line in the answer box.
  • Guessing the output. Run the code first (for example in a Code challenge preview, or in the site's IDE) and copy what it prints.
  • Printing a set of strings (its order changes between runs) or an error message (it changes between Python versions). Use sorted(...) for sets, and ask about errors with a multiple-choice question instead.
  • Using input(): nothing gets typed while the learner reads the code.

Fill in the blanks

Code or a sentence with gaps. The learner either drags words from a word bank into the gaps or types into them.

In the builder:

  1. Shown as: choose Code (highlighted, in a code font) or A sentence.
  2. Answer by: choose Dragging words from a word bank or Typing into the gaps.
  3. Code with gaps (or Sentence with gaps): write the full code or sentence, and type three underscores ___ wherever a gap should be. A gap can be in the middle of a line, such as nums.___(3).
  4. Answers for the gaps: one box appears for each ___, in order. Type the right answer for that gap. If more than one answer should count, separate them with a vertical bar |, for example sort | sort(). In drag mode, the first answer is the one that appears as a chip.
  5. Wrong words for the word bank (drag only): one word per line. These are mixed in with the right answers as chips.
  6. It should print (code only, optional): what the finished code prints, shown under the code as the goal.

Example (code, drag):

Code with gaps:

pets = ['cat', 'dog', 'fish']
last = pets.___()
print(___)
Box Type
Gap 1 pop
Gap 2 last
Wrong words remove on the first line, pets on the second
It should print fish

Example (sentence, typed): The method ___ sorts a list in place. Gap 1: sort | sort()

Common mistakes:

  • Typing two underscores __ or four ____. A gap is exactly three.
  • Putting all the wrong words on one line, separated by commas. Use one per line.
  • A wrong word that also works. Check that no chip in the word bank gives a correct program; if one does, add it as an alternative with |.
  • Typed answers in code must match capital letters exactly (True is not true); in a sentence they don't have to.

Click the line

The learner clicks the line or lines in a piece of code: the bug, the line that raises an error, the line where something happens.

In the builder:

  1. Question: say exactly what to look for: "Which line raises an error?", "Click the line with the bug".
  2. Code: the program, up to about 15 lines.
  3. Right line(s): under the code, every line appears with a number and a checkbox. Tick the right line or lines. At most half of the lines can be right.

Example:

scores = [88, 92, 75]
count = len(scores)
print(scores[count])

Tick line 3: index 3 doesn't exist in a list of three items.

Common mistakes:

  • Editing the code after ticking: line numbers shift. Check the ticks again.
  • More than one defensible answer. If two lines could be "the bug", make the question more specific.

The page tells the learner how many lines to click, so you don't need to say "click 2 lines".

Arrange the code

The lines of a program are shuffled; the learner puts them back in order. You can mix in wrong lines that must be left out.

In the builder:

  1. Question: for example, "Arrange the lines to print the scores from highest to lowest."
  2. Lines in the right order: the whole working program, one line of code per line, in the correct order. Keep the indentation: lines inside a for, if or def start with spaces, exactly as in the real program (Tab inserts 4 spaces). Each line becomes one draggable block.
  3. Wrong lines to mix in (optional): one per line. Learners must leave these out.
  4. It should print (optional): shown as the goal.

Example:

Lines in the right order:

scores = [64, 92, 75]
scores.sort(reverse=True)
for s in scores:
    print(s)

Wrong lines: scores.sorted()

Common mistakes:

  • Lines that could swap places. Only your exact order counts, so if two lines could be swapped and the program still works (two unrelated assignments next to each other, for example), a learner with a correct program gets marked wrong. Make every line depend on the one before.
  • Losing indentation: print(s) without the four spaces is a different line from print(s).
  • A "wrong line" that would actually work somewhere. It should break the program wherever it goes.

Match

The learner pairs each left-hand item with its partner, by dragging or by tapping.

In the builder:

  1. Question: for example, "Match each method to what it does."
  2. Pairs: each row has a Left box and a Match box. Type an item on the left and its partner on the right. Use Add a pair for more rows (3 to 6) and Γ— to remove one. The partners are shuffled into a list that the learner drags from.
  3. Extra matches (optional): partners that fit nothing, one per line, to make guessing harder.

Example:

Left Match
`append(x)` adds x to the end
`insert(i, x)` adds x at position i
`extend(items)` adds every item from another list

Extra matches: removes the first x

Common mistakes: two left items, or two partners, that are the same (each must be unique), and partners so long they're hard to drag. Keep both sides short. The left side can use backticks for code; a partner is shown in a code font only if the whole partner is wrapped in backticks.

Sort into groups

The learner drags items into named groups (2 to 4 of them).

In the builder:

  1. Question: for example, "Sort these into the right group."
  2. For each group: type its name in the top box. In the box under it, type the items that belong to that group, one item per line, pressing Enter after each. Don't separate items with commas: a comma stays part of the item.
  3. Add a group adds another (up to 4); Γ— removes one (at least 2 stay).
  4. In total, use 4 to 10 items, each different. The player mixes all the items together; the learner sorts them back.

Example:

Group name: Changes the list. Items box:

`nums.sort()`
`nums.reverse()`
`nums.append(5)`

Group name: Gives back a new list. Items box:

`sorted(nums)`
`nums.copy()`
`nums[::-1]`

(The backticks around each item show it in a code font. They're optional.)

Common mistakes:

  • Typing a, b, c on one line. That's one item. Press Enter between items.
  • The same item in two groups. Each item must be unique and belong to exactly one group.
  • Fewer than 4 or more than 10 items in total.

Short answer

The learner types a short answer: a method name, a keyword, a value.

In the builder:

  1. Question: for example, "Which list method counts how many times a value appears?"
  2. Code snippet (optional).
  3. Accepted answers: one accepted answer per line. List every form you'd accept, because the learner's answer must match one of them (spaces around the answer don't matter).
  4. Capital letters must match (off by default): turn it on when case matters, such as True versus true.

Example:

Accepted answers box:

count
count()
.count()

Common mistakes: listing only one form when several are reasonable, and asking open questions that have many correct wordings. Short answer works best when there are only a few exact answers.

Code challenge

The learner writes or fixes code in a real editor. It runs in their browser, and they pass when it prints exactly the expected output. This is the strongest test of what someone can actually do.

In the builder:

  1. Question: what the program should do. Be precise about the output: "Print the smallest temperature, then the largest, each on its own line."
  2. Starting code: what the editor starts with. Either a skeleton, such as some variables and a # your code here comment, or buggy code for the learner to fix.
  3. A working solution: a correct program. It's shown to the learner after they check.
  4. Expected output: exactly what a correct program prints, one printed line per line. The learner's output must match it.

Example:

Starting code:

temps = [21.5, 19.0, 24.3]

# your code here

A working solution:

temps = [21.5, 19.0, 24.3]

print(min(temps))
print(max(temps))

Expected output:

19.0
24.3

Test it: in the preview, paste your solution into the editor and press Check. It should say Correct. Then try the starting code: it should not pass.

Common mistakes:

  • Expected output that doesn't match the solution exactly. Run the solution and copy its output.
  • Starting code that already prints the expected output, so it passes without any work.
  • Using input(): there's no one to type an answer while the code is checked.
  • Too many of these in one quiz. The first run loads Python in the browser (a few seconds), so one or two per quiz is plenty.