THINK FIRST·CODE LATER

← All labs

Stevens' power law: how big does it look?

Problem

Input lines: channel value1 value2, where channel is one of length, area, depth, brightness, saturation, electric shock (exponents 1.0, 0.7, 0.67, 0.5, 1.7, 3.5).

For each line compute the data ratio value2/value1 and the perceived ratio (data ratio)ⁿ, and print:

area: data ratio 2.00, perceived ratio 1.62 (n = 0.7) -> underestimated

The verdict is accurate if |perceived − data| / data < 0.05, otherwise underestimated (perceived < data) or overestimated.

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

length 10 20
area 10 20
brightness 10 40
saturation 1 2
area 4 1
What your program must print for v5-2-data-1.txt
length: data ratio 2.00, perceived ratio 2.00 (n = 1) -> accurate
area: data ratio 2.00, perceived ratio 1.62 (n = 0.7) -> underestimated
brightness: data ratio 4.00, perceived ratio 2.00 (n = 0.5) -> underestimated
saturation: data ratio 2.00, perceived ratio 3.25 (n = 1.7) -> overestimated
area: data ratio 0.25, perceived ratio 0.38 (n = 0.7) -> overestimated

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

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

Get-Content v5-2-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-2-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.