Pack and Unpack a Sensor Reading

Easy ⏱ 8 min 77% acceptance ★★★★★ 4.5
Implement pack_reading(temperature, humidity, pressure) that packs the three arguments into a single tuple and returns it. Then implement unpack_reading(reading) that unpacks such a tuple into three named variables in one line and returns a formatted string.

Examples

Example 1
Input
pack_reading(24.5, 60, 1013)
Output
(24.5, 60, 1013)
Explanation

Three values packed into one tuple.

Example 2
Input
unpack_reading((24.5, 60, 1013))
Output
'24.5C, 60%, 1013hPa'
Explanation

Tuple unpacked into temp, hum, pressure in a single assignment.

Constraints

  • unpack_reading must use tuple unpacking, not reading[0]/reading[1]/reading[2] indexing.

Topics

TuplesVariables & Data Types

Companies

AmazonCisco

Hints

Hint 1

A tuple literal (a, b, c) packs values automatically.

Hint 2

temp, hum, pressure = reading unpacks in one line.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.