Edward Tufte's lie factor compares how much a chart's graphic changes with how much the data change. Compute it and judge the chart.
What to build
A program that computes the lie factor of a chart.
Requirements
- Print
data change X%andgraphic change Y%, the relative changes as percentages to one decimal. - Then print
lie factor Z(graphic change ÷ data change, two decimals). If the data change is 0, the lie factor is 1.00 when the graphic change is also 0, otherwise printlie factor infinite. - Finally print
honestif the lie factor is between 0.95 and 1.05 inclusive, otherwisemisleading.
Input
One line: the two data values, then the two drawn sizes.
Output
Four lines.
Constraints
All numbers are over 0 and at most 10⁶.
Example
Input:
18 27.5 0.6 5.3
Output:
data change 52.8%
graphic change 783.3%
lie factor 14.84
misleading
Why it works
Comparing relative changes removes the units of data and graphic, so a ratio of 1 means the picture changes exactly as much as the data, and anything else means it overstates or understates the change.
Examples
18 27.5 0.6 5.3
data change 52.8% graphic change 783.3% lie factor 14.84 misleading
10 20 1 2
data change 100.0% graphic change 100.0% lie factor 1.00 honest
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Each effect is |second − first| ÷ first.
Hint 2
Handle a data effect of 0 separately to avoid dividing by zero.
Hint 3
A lie factor from 0.95 to 1.05 counts as honest.
Solution
Show one correct solution (try it yourself first)
d1, d2, g1, g2 = map(float, input().split())
data = abs(d2 - d1) / d1
graphic = abs(g2 - g1) / g1
print(f"data change {data * 100:.1f}%")
print(f"graphic change {graphic * 100:.1f}%")
if data == 0:
lf = 1.0 if graphic == 0 else None
else:
lf = graphic / data
if lf is None:
print("lie factor infinite")
print("misleading")
else:
print(f"lie factor {lf:.2f}")
print("honest" if 0.95 <= lf <= 1.05 else "misleading")