Skip to main content
🐍 Python Basics 🐍

A Third Choice with elif πŸ”’

Sometimes there are more than two paths. Python adds elif (short for "else if") in the middle:

if score >= 90:
    return "A"
elif score >= 80:
    return "B"
else:
    return "C"

Python checks each line top to bottom and takes the first one that's true.

Your task

Write sign(n) that returns "positive" if n > 0, "negative" if n < 0, and "zero" otherwise.

⚑ 30 XP

🧱 Code blocks

Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.

solution.pyRuns in your browser (Pyodide)
Loading editor…
Tests3 to pass
positive
negative
zero

Run your code to check these.