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.
The three parts
- The editor (
python editor id="even-odd") is where the student writes and runs code.idnames it. - The check (
python-check for="even-odd") never renders — it only runs when the student clicks "Check".formust match the editor'sidexactly, or the check is silently dropped. - The assertions are the grading logic. Each
assertthat fails shows its message;points="10"is the max score if all pass. Without anexamflag on the editor, the student sees pass/fail feedback immediately — addexamto 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.