http://www.weather.gov/rah/rdutemperaturerecords Part 1: Go to the website above
ID: 3705575 • Letter: H
Question
http://www.weather.gov/rah/rdutemperaturerecords
Part 1: Go to the website above and you'll find the daily record report. Write a python program in pseudocode to find the day and year of the lowest recorded temp ever in Raleigh.
Write down the steps to complete Part 1. Now modify your steps for efficiency. We are pretending the data is too large to store in memory for later processing and too time-consuming to read more than once. DO NOT TURN IN A COMPLETE PYTHON PROGRAM!! This is a design exercise! Use pseudocode Your design should include:
The steps in proper sequence
Function definitions including arguments lists
Correct Indentation, or other notation (ENDIF, END LOOP) to indicate statement blocks
Type your design into a Word document or paper what's best for you
Explanation / Answer
Steps to follow :
Step-1 : Open the file from its location and set the access mode as reading.
Step-2 : Read the first line of the file(report) and store the same line as string in some variable.
Step-3 : Now split the line obtained in Step-2 based on the exact delimiter(separator) used in report.
This breaks the line into multiple tokens.
Store these tokens obtained into a list.
Step-4 : Now find the incidices of ‘day’, ‘recorded lowest temperature’, and ‘year’ from the list created in Step-3.
And store each of them into a separate variable.
(As the report is large and may not be stored in memory. We read the report line by line)
Step-5: Create a while loop and start reading file line by line till the end. And perform Step-3 and Step-4 on each line.
Step-6: Whenever the line has recorded lowest temperature lower than the temperature stored in variable, update the temperature, day and year variables by storing the new temperature, day and year value to be as the current line recorded lowest temperature, day and year.
(This way when the whole file/report read, the temperature variable storing the lowest recorded temperature and day and year will be storing the corresponding day and year.)
PseudoCode :
Lowest_Recorded_Temperatue(filePath):
fp <- openFile(filePath)
line <- fp.readLine()
tokens[] <- line.split(delimeter)
day <- tokens[x]
lowRecTemperature <- token[y]
year <- token[z]
while(line):
tokens <- line.split(delimeter)
if(tokens[y] < lowRecTemperature):
lowRecTemperature <- tokens[y]
year <- token[z]
day <- tokens[x]
line <- fp.readLine()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.