THINK FIRST·CODE LATER

← All labs

Measure the lie of a truncated axis

Problem

Input: a line axis_min M, then bars label value (the first bar is the baseline for comparisons).

Print baseline bar: Lucheng = 42, axis starts at 40, then for every other bar: the data change relative to the baseline, the change in drawn bar length (bars are drawn from the axis minimum), and Tufte's lie factor = drawn change / data change (2 decimals), followed by <- misleading (two spaces) if |lie factor − 1| > 0.05:

Ouhai = 44: data +5%, drawn bars +100%, lie factor 21.00  <- misleading

(changes in :+.0% format, values in :g).

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.

v5-3-data-1.txt

axis_min 40
Lucheng 42
Ouhai 44
Longwan 48
What your program must print for v5-3-data-1.txt
baseline bar: Lucheng = 42, axis starts at 40
Ouhai = 44: data +5%, drawn bars +100%, lie factor 21.00  <- misleading
Longwan = 48: data +14%, drawn bars +300%, lie factor 21.00  <- misleading

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 < v5-3-data-1.txt

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

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