CP1 / COURSE HOME

Week 03 / Describe and decide

Turn an operating rule into a decision

Make every combination of conditions have a clear outcome.

A display communicates a result. The next step is to make a decision from it. Before choosing a Python branch, we need an operating rule that two people would interpret the same way.

In our simulated motor test, a run request is present. The motor may be enabled only when the guard is closed and the temperature is below 60 °C.

Start with the problem

Try this first.

Decide what the model should do with a closed guard at 59 °C, a closed guard at 60 °C, and an open guard at 25 °C. Give the reason for each decision.

Why this week's tool?

Comparisons express each condition. if/else and and combine them into the written rule. We will check the decision table against the code.

By the end: Explain an ENABLE or DENY result from the rule, including the exact threshold. This exercise models a decision; it does not implement a hardware interlock.

The idea behind the program

Requirements must resolve equality

Below 60 means strictly less than 60. At 60, the rule denies enable. Replacing < with <= changes the requirement, even if most sample readings produce the same answer.

Combine conditions deliberately

Both prerequisites must hold, so use and. With or, a closed guard could permit enable at excessive temperature. A truth table exposes this mistake more clearly than a long program.

State the model boundary

The example assumes a Boolean guard signal and a valid numeric temperature. It says nothing about sensor freshness, broken wires, actuator response or certified interlocks. An enable decision in software is not evidence that motion is safe.

A short Python example

Read the example alongside the explanation. Run it in a new notebook cell and change one input to see how it behaves.

guard_closed = True
temperature_c = 60.0
if guard_closed and temperature_c < 60:
    print('ENABLE')
else:
    print('DENY')

Example output

DENY

A condition encodes a rule and its boundaries

A Boolean expression answers a precise yes/no question. An if/elif chain chooses the first satisfied branch; separate if statements ask separate questions. Translate the operating rule before choosing the syntax.

Draw or trace

Draw a temperature number line with the accepted interval 10 ≤ temperature ≤ 40, then a second gate for guard_closed. Operation requires both gates.

Predict before running. Classify temperatures 9, 10, 40 and 41 with a closed guard. What changes when the guard is open?

Trace and explanation — after your prediction
  1. With a closed guard, 10 and 40 pass because both endpoints are included.
  2. 9 and 41 fail the interval test.
  3. With an open guard, every temperature fails the combined and condition.

The condition means “inside the interval AND guard closed.” Using or would allow operation when only one requirement holds. This is a logic exercise, not a complete machine-safety controller.

Change one thing. Change the specification to exclude the upper endpoint. Identify exactly one comparison that must change and one test that detects it.

Türkçe: Önce işletme kuralını ve sınırlarını çiz. and bütün koşulları ister; or yalnızca birinin sağlanmasıyla doğru olabilir.

Examples and variations

Each example changes something about the same problem. Open the ones you want to explore and follow the worked explanation.

01Nominal request

Guard closed = True; temperature = 59 °C

Question: Enable or deny? Which prerequisites are satisfied?

  1. guard_closed → True
  2. 59 < 60 → True
  3. True and True → True

ENABLE in the teaching model

Both conditions hold. This conclusion depends on the stated assumptions about the inputs.

02Exact threshold

Guard closed = True; temperature = 60 °C

Question: Does 'below 60' include 60?

  1. guard_closed → True
  2. 60 < 60 → False
  3. True and False → False

DENY

Equality belongs to the denied branch. Test 59.9, 60.0 and 60.1 rather than only easy values.

03Logical operator fault

Guard open; temperature = 25 °C; compare and with or

Question: Which expression incorrectly permits enable?

  1. False and True → False
  2. False or True → True
  3. The or version accepts just one prerequisite

Correct rule denies; or version enables

One counterexample disproves the faulty implementation. Keep it as a regression check.

See the Colab code run

Interactive walkthroughs of Conditionals & Decision Making. Enable JavaScript to step through code, variables, collections and output. The companion notebook remains available below.

Work on it in Colab

Use the notebook to try the ideas yourself. The steps below connect this week's example to the programming practice.

  1. Write all four combinations of guard state and temperature condition as a decision table. Agree on the output before coding.
  2. Run the model for each row, then add 59.9, 60.0 and 60.1 °C with the guard closed.
  3. Change and to or and find the smallest counterexample. Ask a partner to explain the fault from the table.
  4. Identify one unmodelled input failure, such as a stale temperature. Describe the information you would need before extending the rule.

Something to take away: A four-row decision table, three threshold checks, and one counterexample that catches the wrong logical operator.

Suggested exercises, downloads & solutions

Read the notebook's teaching cells before these exercises.

  • EX01 Positive, Negative, or Zero (Easy)
  • EX03 Grade Calculator (Medium)
  • EX06 Triangle Validator (Medium)
Download notebookWorked solutions

Use the notebook's core and optional labels to choose your workload. This activity fits within guided class time.

Optional notes & guidance
My notes
Using AI or working with a partner

Give AI the written rule and ask for code. Review the operators without running it first. Then present the guard-open/cool-temperature counterexample and check the revised version against every row.

You can also review the supplied example with a partner. Use the same inputs to compare the reasoning. Follow the syllabus rules for assessed work.