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.