THINK FIRST·CODE LATER

← All labs

Fact-check a generated caption

Problem

Input: a CSV district,month,pm25, a line ---, then a caption (sentences ending with . or !).

Check each sentence with these rules (first matching rule):

  • <District> rose|fell by N% — compare with (last − first)/first of that district (months in order): supported if the direction matches and |actual| is within 1 percentage point of N; print SUPPORTED (actual -23.1%): <sentence> or NOT SUPPORTED (actual -5.3%): …;
  • <District> had the highest average… — supported if the district has the highest mean: … (highest is Lucheng at 46.3);
  • The city average was N / city average was N — supported if the mean of all rows is within 0.5: … (actual 41.7);
  • otherwise UNCHECKED: <sentence> (no rule for this kind of claim - needs a human).

Finish with 3 of 4 checkable claims supported.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

v12-4-data-1.txt

district,month,pm25
Lucheng,2026-01,52
Lucheng,2026-02,47
Lucheng,2026-03,40
Ouhai,2026-01,38
Ouhai,2026-02,37
Ouhai,2026-03,36
---
Lucheng fell by 23% between January and March. Ouhai fell by 20%. Lucheng had the highest average PM2.5. The city average was 42. Air quality improved because of the new bike lanes.
What your program must print for v12-4-data-1.txt
SUPPORTED (actual -23.1%): Lucheng fell by 23% between January and March.
NOT SUPPORTED (actual -5.3%): Ouhai fell by 20%.
SUPPORTED (highest is Lucheng at 46.3): Lucheng had the highest average PM2.5.
SUPPORTED (actual 41.7): The city average was 42.
UNCHECKED: Air quality improved because of the new bike lanes. (no rule for this kind of claim - needs a human)
3 of 4 checkable claims supported

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), in the folder that holds both files:

python my_lab.py < v12-4-data-1.txt

Windows PowerShell (the default terminal of VS Code on Windows) does not understand <:

Get-Content v12-4-data-1.txt | python my_lab.py

PyCharm: Run → Edit Configurations → tick Redirect input from and choose the file.

Jupyter: put this at the top of the cell that holds your program:

import sys
sys.stdin = open("v12-4-data-1.txt", encoding="utf-8")

Write it here, in Jupyter or in your IDE, then paste it. Run it on the sample input yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.