\[ \begin{align}\begin{aligned}\newcommand\blank{~\underline{\hspace{1.2cm}}~}\\% Bold symbols (vectors) \newcommand\bs[1]{\mathbf{#1}}\\% Differential \newcommand\dd[2][]{\mathrm{d}^{#1}{#2}} % use as \dd, \dd{x}, or \dd[2]{x}\\% Poor man's siunitx \newcommand\unit[1]{\mathrm{#1}} \newcommand\num[1]{#1} \newcommand\qty[2]{#1~\unit{#2}}\\\newcommand\per{/} \newcommand\squared{{}^2} \newcommand\cubed{{}^3} % % Scale \newcommand\milli{\unit{m}} \newcommand\centi{\unit{c}} \newcommand\kilo{\unit{k}} \newcommand\mega{\unit{M}} % % Percent \newcommand\percent{\unit{{\kern-4mu}\%}} % % Angle \newcommand\radian{\unit{rad}} \newcommand\degree{\unit{{\kern-4mu}^\circ}} % % Time \newcommand\second{\unit{s}} \newcommand\s{\second} \newcommand\minute{\unit{min}} \newcommand\hour{\unit{h}} % % Distance \newcommand\meter{\unit{m}} \newcommand\m{\meter} \newcommand\inch{\unit{in}} \newcommand\foot{\unit{ft}} % % Force \newcommand\newton{\unit{N}} \newcommand\kip{\unit{kip}} % kilopound in "freedom" units - edit made by Sri % % Mass \newcommand\gram{\unit{g}} \newcommand\g{\gram} \newcommand\kilogram{\unit{kg}} \newcommand\kg{\kilogram} \newcommand\grain{\unit{grain}} \newcommand\ounce{\unit{oz}} % % Temperature \newcommand\kelvin{\unit{K}} \newcommand\K{\kelvin} \newcommand\celsius{\unit{{}^\circ C}} \newcommand\C{\celsius} \newcommand\fahrenheit{\unit{{}^\circ F}} \newcommand\F{\fahrenheit} % % Area \newcommand\sqft{\unit{sq\,\foot}} % square foot % % Volume \newcommand\liter{\unit{L}} \newcommand\gallon{\unit{gal}} % % Frequency \newcommand\hertz{\unit{Hz}} \newcommand\rpm{\unit{rpm}} % % Voltage \newcommand\volt{\unit{V}} \newcommand\V{\volt} \newcommand\millivolt{\milli\volt} \newcommand\mV{\milli\volt} \newcommand\kilovolt{\kilo\volt} \newcommand\kV{\kilo\volt} % % Current \newcommand\ampere{\unit{A}} \newcommand\A{\ampere} \newcommand\milliampereA{\milli\ampere} \newcommand\mA{\milli\ampere} \newcommand\kiloampereA{\kilo\ampere} \newcommand\kA{\kilo\ampere} % % Resistance \newcommand\ohm{\Omega} \newcommand\milliohm{\milli\ohm} \newcommand\kiloohm{\kilo\ohm} % correct SI spelling \newcommand\kilohm{\kilo\ohm} % "American" spelling used in siunitx \newcommand\megaohm{\mega\ohm} % correct SI spelling \newcommand\megohm{\mega\ohm} % "American" spelling used in siunitx % % Capacitance \newcommand\farad{\unit{F}} \newcommand\F{\farad} \newcommand\microfarad{\micro\farad} \newcommand\muF{\micro\farad} % % Inductance \newcommand\henry{\unit{H}} \newcommand\H{\henry} \newcommand\millihenry{\milli\henry} \newcommand\mH{\milli\henry} % % Power \newcommand\watt{\unit{W}} \newcommand\W{\watt} \newcommand\milliwatt{\milli\watt} \newcommand\mW{\milli\watt} \newcommand\kilowatt{\kilo\watt} \newcommand\kW{\kilo\watt} % % Energy \newcommand\joule{\unit{J}} \newcommand\J{\joule} % % Composite units % % Torque \newcommand\ozin{\unit{\ounce}\,\unit{in}} \newcommand\newtonmeter{\unit{\newton\,\meter}} % % Pressure \newcommand\psf{\unit{psf}} % pounds per square foot \newcommand\pcf{\unit{pcf}} % pounds per cubic foot \newcommand\pascal{\unit{Pa}} \newcommand\Pa{\pascal} \newcommand\ksi{\unit{ksi}} % kilopound per square inch % NOTE: do NOT define \bar -- it is the built-in LaTeX accent used by \bar{x}, % \bar{y} (sample means). Redefining it made those render as the word "bar". \newcommand\barunit{\unit{bar}} \end{aligned}\end{align} \]

Nov 16, 2026 | 354 words | 4 min read

9.2.1. ICA: Factory Alarm System#

In this activity, you will …#

  • Draw a flowchart that includes conditions for an alarm system

  • Review and reflect on repetitions in the flowchart

  • Implement your flowchart into a python program

  • Discuss in small groups the inefficiencies in your program and how to improve them

  • Learn about a future Python unit topic and how it may help with these annoyances/inefficiencies while coding

Learning Objectives#

  • PR01: Programming Standards

  • PR04: Modular Programming

  • PR05: Code Structures

  • PR07: Test Cases and Tracking

  • UC05: System Efficiency and Performance

Activity Instructions#

A factory monitors pressure (psi) and temperature (°C). Two events can happen, and both need to be recorded the same way (print the reading and the reason):

  1. ALARM if pressure > 300, OR if pressure > 250 AND temperature > 80

  2. WARNING if pressure > 200, OR if pressure > 150 AND temperature > 60

Whenever either an alarm or a warning fires (input from user), the event must be recorded the same way. For example:

Step 1#

In teams of 2-4, draw a flowchart for the factory monitoring python program. Draw your flowchart using paper provided by your UGTAs or use draw.io.

View Sample Flowchart

Step 2#

Review your flowchart and ask yourself the following questions.

  • Does your chart repeat itself?

  • If so, how often does this repetition occur?

  • If your chart does repeat itself, how might you revise it be more efficient?

Note

We are currently limited by our coding knowledge, so it’s okay to think outside the box and share general solutions when answering the last question.

Step 3#

Implement your flowchart directly in Python using only what we have learned so far (if/elif/else and boolean operators).

View Sample Solution
# example user inputs
pressure = 220
temperature = 70

if pressure > 300 or (pressure > 250 and temperature > 80):
    print(f"EVENT: ALARM | pressure={pressure}, temperature={temperature}")
elif pressure > 200 or (pressure > 150 and temperature > 60):
    print(f"EVENT: WARNING | pressure={pressure}, temperature={temperature}")

Step 4#

Ask one or two other teams around you: “How can we improve our code?”

Discuss your thoughts and then view information in the dropdown below:

How can we improve our code?

One annoying aspect of writing the code with conditional/selection structures is the repeated print statements. Imagine writing 5-10 conditions with similar print statements … this would create a lot of repetition and inefficiency in the code.

Functions are built to solve this problem. We will learn about functions in our next class and return to similar examples where functions can be used to write more efficient code.