AI: A reflex thermostat

Write the simplest kind of agent: one rule per percept.

What to build

A simple reflex agent that decides, for each temperature reading, whether to heat, cool or do nothing.

Requirements

  • Below the low limit the action is heat; above the high limit it is cool; otherwise off.
  • Print T: action for each reading, then heat H, cool C, off O.

Input

Line 1: the low and high limits. Line 2: n. Line 3: n whole-number readings.

Output

n lines, then the counts.

Constraints

n ≤ 100; readings may be negative; low ≤ high.

Example

Input:

18 22
5
17 18 23 22 15

Output:

17: heat
18: off
23: cool
22: off
15: heat
heat 2, cool 1, off 2

Why it works

The right action depends only on the current reading, so a fixed rule for each percept is enough: that is a simple reflex agent.

Examples

Example 1 · Input
18 22
5
17 18 23 22 15
Expected output
17: heat
18: off
23: cool
22: off
15: heat
heat 2, cool 1, off 2
Example 2 · Input
20 20
3
20 21 19
Expected output
20: off
21: cool
19: heat
heat 1, cool 1, off 1

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Compare each reading with the low and high limits; nothing else is needed.

Hint 2

Count the actions as you print them.

Solution

Show one correct solution (try it yourself first)
low, high = map(int, input().split())
input()
counts = {"heat": 0, "cool": 0, "off": 0}
for t in map(int, input().split()):
    action = "heat" if t < low else "cool" if t > high else "off"
    counts[action] += 1
    print(f"{t}: {action}")
print(f"heat {counts['heat']}, cool {counts['cool']}, off {counts['off']}")

Lesson: Intelligent agents →