Picnic Weather

Data with PythonEasy+10 XP+10

Picnic Weather

A picnic club looks back over its weather records. Day i has a temperature temps[i] (in °C) and a rainfall rain[i] (in mm), so the two lists line up day by day.

A day counts as picnic weather when both of these are true:

  • its temperature is at least low and at most high,
  • its rainfall is exactly 0.

Task: write picnic_days(temps, rain, low, high) returning a tuple (kept, count, share):

  • kept — the temperatures of the picnic-weather days, as a plain list, in the same order as the records,
  • count — how many days were picnic weather,
  • share — the fraction of all the days that were picnic weather, rounded to 4 decimal places.

There is always at least one day of records.

Example

31 is too hot, 22 had rain, and 18 and 15 are too cold.

Examples

temps = [18, 24, 31, 22, 15, 26]
rain = [0, 0, 0, 2.5, 0, 0]
low = 20
high = 28
returns ([24, 26], 2, 0.3333)
temps = [20, 28, 19.5, 28.5, 25]
rain = [0, 0, 0, 0, 0.1]
low = 20
high = 28
returns ([20, 28], 2, 0.4)

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run