THINK FIRST·CODE LATER

← All labs

Detect a cherry-picked time window

Problem

Input: a line window START END (months YYYY-MM), then a CSV month,value (the full series).

Compute least-squares slopes (value against position 0, 1, 2, …) and relative changes (last vs. first value) for the full series and for the window. Print:

full series 2025-01..2025-12 (12 months): slope -0.75/month (falling), change -23%
shown window 2025-06..2025-09 (4 months): slope +1.70/month (rising), change +12%
WARNING: the window reverses the long-term trend (cherry-picking risk)

The last line is the reversal warning if the slopes have different signs; else WARNING: the window exaggerates the long-term trend if |window slope| > 2 × |full slope|; else window is consistent with the long-term trend.

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.

v6-4-data-1.txt

window 2025-06 2025-09
month,value
2025-01,48
2025-02,47
2025-03,45
2025-04,44
2025-05,43
2025-06,40
2025-07,41
2025-08,43
2025-09,45
2025-10,41
2025-11,39
2025-12,37
What your program must print for v6-4-data-1.txt
full series 2025-01..2025-12 (12 months): slope -0.75/month (falling), change -23%
shown window 2025-06..2025-09 (4 months): slope +1.70/month (rising), change +12%
WARNING: the window reverses the long-term trend (cherry-picking risk)

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 < v6-4-data-1.txt

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

Get-Content v6-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("v6-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.