Control Flow and Functions

English translation

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

Before practice

01 Which group contains a value exactly equal to the Threshold?

Description

Including or excluding equality in comparisons changes decisions at the boundary.

02 What should be bundled into a function to apply the same decision rule to multiple inputs?

Description

Bundle the inputs and decision rule into a function, with the Threshold as a separate argument.

Practice

Preview practice notebookDownload practice notebook

1. 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

Items to record and points to check
Score
Loop result
Function result
Match status

Points to check

  • Did you actually test the boundary value 60?

2. 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

Items to record and points to check
Threshold
Decisions for the four scores
Number of passing students
Scores whose decisions changed

Points to check

  • Did you record the decision for a value equal to the cutoff score?

3. 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

Items to record and points to check
Input scores
Prediction before execution
Actual return value
Boundary value and empty input handling

Points to check

  • Did you run the same function on an empty input too?