Control Flow and Functions · Learning Materials

English translation

Topics covered

A single boundary value changes the decision. Turn a conditional into a function and compare ordinary and boundary inputs.

Define the Condition Boundary First

score>60 and score≥60 give different results at 60. Test immediately below, at, and immediately above the boundary to check the comparison rule.

Reuse with a Function

When applying the same decision rule to multiple samples, define the inputs, Threshold, and outputs as the function contract. Handle empty data and nonnumeric inputs separately from valid scores.

Worked example

Scores=[45,60,75,90], and the passing criterion is 60 or higher.

scores=[45,60,75,90]
def pass_flags(values,threshold=60):
    return [v>=threshold for v in values]
print(pass_flags(scores))
[False, True, True, True]

Reference example

View more examples

Reference materials