Problem 162365 · easy · Level 01 Prerequisites & Setup

Temperature Swing

lists · statistics · max-by-hand

The daily temperature swing is the difference between the hottest and the coldest reading. Write temperature_swing(temps) that returns highest - lowest. Return 0 if the list is empty.

Examples

Input:  temps = [12, 18, 9, 15]
Output: 9

Input:  temps = []
Output: 0

Constraints

  • 0 <= len(temps) <= 5000

Goals

  • Track both the largest and smallest value in one loop
  • Compute the range of a data set
Starting Python…