Control Flow and Functions

English translation

Learning objectives

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

Conditions and loops

Starting conditions

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

Procedure

  1. Use for and if to determine whether each score passes.
  2. Implement the same process as pass_flags(scores,threshold) and compare the two results.

Results to retain

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

Record results and self-check

Score:

Loop result:

Function result:

Match:

Points to check

Changing the Threshold

Starting conditions

Compare passing-student counts and boundary samples at threshold=50,60,80.

Procedure

  1. Call pass_flags with each Threshold in 50,60,8050,60,80. Keep the four scores unchanged.
  2. Tabulate the four pass/fail decisions and the passing-student count for each Threshold. Check whether the comparison operator used when a sample's score equals the Threshold is >=.
  3. Identify scores whose decisions changed with the Threshold and explain why.

Results to retain

thresholds=[50,60,80]

Record results and self-check

Threshold:

Decisions for the four scores:

Number of students who pass:

Scores whose decisions changed:

Points to check

Checking Other Inputs

Starting conditions

Check the function's boundary values using scores [59,60,61] and an empty List.

Procedure

  1. Keep Threshold 60 and write the expected function return values for scores [59,60,61] and an empty List before running.
  2. Call pass_flags on both inputs and record expected and actual return values side by side. Explain the decision for score 60 and the form of the return value for an empty input.

Results to retain

# Use the preceding activity's data and functions to check the specified new examples.

Record results and self-check

Input scores:

Prediction before running:

Actual return value:

Boundary value and empty input handling:

Points to check