-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathexercise_12.py
36 lines (30 loc) · 1020 Bytes
/
exercise_12.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#This program accepts a sequence of average daily temps and computes
#the running total of cooling and heating degree days
def main():
fname = input("Enter filename: ")
infile = open(fname, "r")
coolDeg = 0
heatDeg = 0
avgTemp = 1
while avgTemp != None:
#Accept input in degrees
for avgTemp in infile.readlines():
print(avgTemp)
try:
avgTemp = int(avgTemp[0:-1])
if avgTemp < 60:
coolDeg = coolDeg + abs((avgTemp - 60))
elif avgTemp > 80:
heatDeg = heatDeg + (avgTemp - 80)
else:
avgTemp = avgTemp
except ValueError:
if avgTemp[0:-1] == '':
break
else:
return False
finally:
infile.close()
break
print("The cooling degree-day is {0} and the heating degree-day is {1}.".format(coolDeg, heatDeg))
main()