Ein frei kopier- und anpassbares Lehrmittel von eduskript.org

First Steps: Computer Science

One small lesson, start to finish: an explanation, an exercise students run themselves, and a check that scores it. Copy the markdown below onto a new page and adjust.

The markdown

## Even or odd

A number is even if dividing it by 2 leaves no remainder — in Python, `n % 2 == 0`.

Write a function `is_even(n)` that returns `True` if `n` is even, `False` otherwise.

```python editor id="even-odd"
def is_even(n):
    # your code here
    pass
```

```python-check for="even-odd" points="10"
assert is_even(4) == True, "is_even(4) should be True"
assert is_even(7) == False, "is_even(7) should be False"
assert is_even(0) == True, "is_even(0) should be True"
```

What renders

Even or odd

A number is even if dividing it by 2 leaves no remainder — in Python, n % 2 == 0.

Write a function is_even(n) that returns True if n is even, False otherwise.

PythonLoading editor…
def is_even(n):
    # your code here
    pass

The three parts

  • The editor (python editor id="even-odd") is where the student writes and runs code. id names it.
  • The check (python-check for="even-odd") never renders — it only runs when the student clicks "Check". for must match the editor's id exactly, or the check is silently dropped.
  • The assertions are the grading logic. Each assert that fails shows its message; points="10" is the max score if all pass. Without an exam flag on the editor, the student sees pass/fail feedback immediately — add exam to grade silently during a real assessment.

That's a complete, self-grading exercise. For turtle graphics, multi-file editors, SQL with a bundled database, and exam-mode grading, see Code Editors & Scoring in the Components section.