3. Parsons Puzzles — Feature Showcase

This page demonstrates the full range of options available in the Parsons puzzle directive.

3.1. Basic Puzzle

Reverse a list

  • 2 |
    for x in reversed(xs):
  • 4 |
    print(result)
  • 1 |
    result = []
  • 3 |
    result.append(x)

Column 1


3.2. Factorial Puzzle

Factorial function

  • 1 |
    def factorial(n):
  • 2 |
    if n == 0:
  • 3 |
    return 1
  • 4 |
    else:
  • 6 |
    print(factorial(5))
  • 5 |
    return n * factorial(n-1)

Column 1


3.3. Order-Only Check

Order matters, indent ignored

  • 1 |
    for i in range(3):
  • 2 |
    print(i)

Column 1


3.4. Indent-Only Check

Indentation matters, order ignored

  • 1 |
    for i in range(3):
  • 2 |
    print(i)

Column 1


3.5. Multi-Column Puzzle

Separate Input and Output

  • 5 |
    print(result)
  • 3 |
    for x in xs:
  • 4 |
    result.append(x * 2)
  • 1 |
    xs = [1, 2, 3]
  • 2 |
    result = []

Input

Output


3.6. Three Column Puzzle

Three stages

  • 2 |
    result = []
  • 4 |
    result.append(x * 2)
  • 5 |
    print(result)
  • 1 |
    xs = [1, 2, 3]
  • 3 |
    for x in xs:

Setup

Loop

Output


3.7. Puzzle with Distractors

Sum a list

  • 1 |
    total = 0
  • 4 |
    print(total)
  • 3 |
    total += x
  • 5 |
    print("wrong answer")   # distractor
  • 2 |
    for x in xs:
  • 6 |
    xs = "not a list"       # distractor

Column 1


3.8. Custom Buttons

Custom button labels

  • 2 |
    squares = [n*n for n in nums]
  • 1 |
    nums = [1, 2, 3]
  • 3 |
    print(squares)

Column 1


3.9. Python-Side Shuffle

Square numbers

  • 2 |
    squares = [n*n for n in nums]
  • 3 |
    print(squares)
  • 1 |
    nums = [1, 2, 3]

Column 1


3.10. Client-Side Shuffle

Square numbers

  • 1 |
    nums = [1, 2, 3]
  • 2 |
    squares = [n*n for n in nums]
  • 3 |
    print(squares)

Column 1


3.11. Accessibility Note

Learners can use keyboard navigation as well as drag - and - drop:

  • Arrow Up/Down: move a line within its list.

  • Arrow Left/Right: adjust indentation.

  • Tab: focus different lines.