commit 09c346526b74f389a5ed9dbb6cd1cb23209db673 Author: Benjamin Hackl Date: Fri Oct 30 14:24:43 2026 +0100 feat: sick bay software diff --git a/README.md b/README.md new file mode 100644 index 0000000..74b8c55 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Sick bay software of the SS Probably Fine + +Run `python3 sickbay.py`. diff --git a/sickbay.py b/sickbay.py new file mode 100644 index 0000000..9c3c1be --- /dev/null +++ b/sickbay.py @@ -0,0 +1,76 @@ +"""Sick bay software of the SS Probably Fine. + +Maintained by Dr. Honk, who does not believe in type hints. Yet. + +Temperatures are measured in degrees Celsius, unless stated otherwise. +""" + +import random + +PATIENTS = { + "Captain Vega": 37.1, + "Lt. Byte": 38.6, + "Cmdr. Nova": 36.8, + "Ensign Pixel": 39.2, +} + +FEVER_THRESHOLD = 38.0 + + +def to_celsius(value, unit): + """Convert a temperature in the given unit ("C", "F", or "K") to Celsius.""" + if unit == "C": + return value + if unit == "F": + return (value - 32) * 5 / 9 + if unit == "K": + return value - 273.15 + raise ValueError(f"Unknown unit: {unit}") + + +def has_fever(celsius): + return celsius >= FEVER_THRESHOLD + + +def fever_patients(patients): + """Return the names of all patients with fever, in alphabetical order.""" + return sorted(name for name, celsius in patients.items() if has_fever(celsius)) + + +def find_patient(query, patients): + """Return the full name of the first patient whose name contains `query`.""" + for name in patients: + if query.lower() in name.lower(): + return name + return None + + +def average_temperature(temperatures): + if not temperatures: + return "n/a" + return sum(temperatures) / len(temperatures) + + +def pick_random(items): + """Return a random element of a list.""" + return random.choice(items) + + +def greet(query, patients): + name = find_patient(query, patients) + return f"Quack, {name.upper()}! Dr. Honk will see you now." + + +def ward_report(patients): + average = average_temperature(list(patients.values())) + lines = [f"Patients: {len(patients)}", f"Average temperature: {round(average, 1)} °C"] + for name in fever_patients(patients): + lines.append(f" FEVER: {name}") + return "\n".join(lines) + + +if __name__ == "__main__": + print(ward_report(PATIENTS)) + print(greet("byte", PATIENTS)) + print(f"Today's volunteer for the flu shot: {pick_random(list(PATIENTS))}") + print(f"101.3 °F = {to_celsius(101.3, 'F'):.1f} °C")