from pykubegrader.tokens.validate_token import validate_token
validate_token('type the key provided by your instructor here')
# You must make sure to run all cells in sequence using shift + enter or you might encounter errors
from pykubegrader.initialize import initialize_assignment
responses = initialize_assignment("3_if_else_q", "week_4", "lecture", assignment_points = 8.0, assignment_tag = 'week4-lecture')
# Initialize Otter
import otter
grader = otter.Notebook("3_if_else_q.ipynb")
๐ป Activity 5.1: Nuclear Plant Temperature Alert#
We have just covered the relationship of a process value to a desired set point and discussed the importance of redundancy, especially in systems that have the potential to harm people.
Problem Statement#
Consider a nuclear reactor. A meltdown would be sufficiently catastrophic that the temperature of the cooling water around the nuclear fuel rods is monitored by four sensors.
An alarm should go off if:
Condition 1: Any two sensor readings differ by strictly more than 8 degrees.
Condition 2: Any of the two sensors report a temperature greater than 100 degrees Celsius.
Write a function coolingWaterAlarm(t1, t2, t3, t4)
where t1
, t2
, t3
, and t4
are the temperature readings for sensor 1, sensor 2, sensor 3, and sensor 4, respectively.
The function should:
- Print Alarm! Temperatures differ.
if the first condition is met.
- Print Alarm! Temperatures exceed 100 deg Celsius.
if the second condition is met.
- Print Normal operation.
if neither condition is met.
Implementation#
We have provided the function for you to use.
Convert the temperature readings to a list,
tlist
.Check if the difference between the maximum and minimum values of
tlist
is strictly greater than 8. If so, print the first alarm message. You should use themax()
andmin()
functions.Check if the maximum value of
tlist
is greater than 100. If so, print the second alarm message.If neither condition is met, print the normal operation message.
def coolingWaterAlarm(t1, t2, t3, t4):
...
# Test the function
coolingWaterAlarm(93, 95, 96, 101)
coolingWaterAlarm(95, 103, 96, 101)
coolingWaterAlarm(90, 95, 96, 101)
coolingWaterAlarm(90, 95, 96, 92)
grader.check("cooling-water-problems")
Submitting Assignment#
Please run the following block of code using shift + enter
to submit your assignment, you should see your score.
from pykubegrader.tokens.validate_token import validate_token
validate_token()
from pykubegrader.submit.submit_assignment import submit_assignment
submit_assignment("week4-lecture", "3_if_else_q")