Learn / Python / Conditions: pass or fail

Python, lesson 3 of 6

Conditions: pass or fail

Programs make decisions with if and else. The indented lines run only when the condition is true:

def check(temp):
    if temp > 100:
        return "too hot"
    else:
        return "ok"

def makes a function: a named piece of code you can call with different values. return sends the answer back. Comparisons: > < >= <= == !=.

Your turn

Write grade(score): return "pass" when the score is 50 or more, otherwise "fail".

Press Run to see what your code prints.