0% found this document useful (0 votes)
6 views3 pages

Weather Data Fluctuation Analysis

Uploaded by

brainydwivedi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Weather Data Fluctuation Analysis

Uploaded by

brainydwivedi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Q4: Problem Statement

Sarah, a meteorologist, is tracking daily weather data for the past week and needs to analyze
temperature fluctuations. She has been provided with the temperature data for each day of the
week. Sarah wants to calculate the fluctuation in temperature for each day, compute the average
fluctuation, and predict the temperature for the next day based on these fluctuations.
Sarah needs your help to implement a system that will process the weather data, compute these
fluctuations, and predict the temperature for the next day.
Example:
Input:
5
Monday
20.5
Tuesday
22.0
Wednesday
23.5
Thursday
21.0
Friday
22.5
Output:
{'Tuesday': 1.5, 'Wednesday': 1.5, 'Thursday': -2.5, 'Friday': 1.5}
1.25
23.00
Explanation:
Fluctuations:
From Monday to Tuesday: 22.0 - 20.5 = 1.5
From Tuesday to Wednesday: 23.5 - 22.0 = 1.5
From Wednesday to Thursday: 21.0 - 23.5 = -2.5
From Thursday to Friday: 22.5 - 21.0 = 1.5
Average fluctuation: (1.5 + 1.5 - 2.5 + 1.5) / 4 = 1.25
Predicted temperature for Saturday: 22.5 + 1.25 = 23.0
Input format :
The first line of input consists of an integer n, representing the number of days for which the
weather data is provided.
The next n lines contain:
A string representing the day of the week (e.g., "Monday", "Tuesday", etc.).
A float representing the temperature for that day.
Output format :
The first line of output prints the fluctuations for each day (from the second day onward), where
the fluctuation is the difference in temperature between the current day and the previous day.
The output should be a dictionary with the day of the week as the key and the fluctuation as the
value.
The second line prints the average fluctuation of temperatures between the days, formatted to
two decimal places.
The third line prints the predicted temperature for the next day, formatted to two decimal places,
based on the average fluctuation from the last day.
Pseudocode-
INPUT n
l1 ← [] // days
l2 ← [] // temperatures
l3 ← [] // days from second day onward
l4 ← [] // differences between consecutive temps

FOR i ← 0 TO 2*n - 1 DO
IF i % 2 == 0 THEN
day ← INPUT (string)
APPEND day TO l1
ELSE
temp ← INPUT (float)
APPEND temp TO l2
END IF
END FOR

// shift days so each aligns with its diff from previous day
FOR j ← 1 TO length(l1) - 1 DO
APPEND l1[j] TO l3
END FOR

// compute consecutive differences


FOR k ← 0 TO length(l2) - 2 DO
y ← l2[k+1] - l2[k]
APPEND y TO l4
END FOR

avg ← (SUM of l4) / length(l4)


d ← DICTIONARY formed by pairing l3 with l4 // zip(l3, l4)

PRINT d
PRINT avg formatted to 2 decimals
c ← avg + l2[length(l2) - 1]
PRINT c formatted to 2 decimals

You might also like