View Single Post
Old 2016-11-09, 01:51   #1
Nov 2016

1 Posts
Default Python Coding Help?

I have a problem. I don't know how to get input from users and calculate in the way I need to. Here is my prompt for the code..

Heating and cooling degree-days are measures used by utility companies to estimate energy requirements. If the average temperature for a day is below 60, then the number of degrees below 60 is added to the heating degree-days. If the temperature is above 80, the amount over 80 is added to the cooling degree-days. Write a program that accepts a sequence of average daily temps and computes the running total of cooling and heating degree-days. The program should print these two totals after all the data has been processed.

For this exercise, the program should get input from the Penn State Climatologist website. Start with this code, which prints average temperatures recorded at the Harrisburg airport over the past year.

from urllib.request import Request, urlopen

def getAverageTemps(startDate, endDate):
url = ""
data = ("siteid=KMDT" + # KMDT is Harrisburg International Airport.
"&datastart=" + startDate +
"&dataend=" + endDate +
"&db=faa_daily" +
"&choices[]=date" +
"&choices[]=temp_avg" +
"&filetype=file" +
dataBytes = data.encode()
request = Request(url, dataBytes)
response = urlopen(request).read().decode()
lines = response.split("\n")
temps = []

for line in lines:
if line[0:4].isnumeric():
temp = line.split(",")[1]

return temps

def main():
print(getAverageTemps("2013-11-01", "2014-10-31"))

if __name__ == "__main__":

(Write your program so that it inputs start and end dates of the form M/D/Y and converts them to the form required by the Penn State Climatologist site)

Here is a sample output.

This program computes the heating and cooling
degree-days for Harrisburg, PA, over a period
of time, using data from the Penn State
Climatologist website.

Start date (e.g., 1/1/2013)? 11/1/2013
End date (e.g., 12/31/2013)? 10/31/2014

Heating degree-days: 4510.13
Cooling degree-days: 13.64
kelzo is offline   Reply With Quote