-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachorroProject4.py
More file actions
66 lines (60 loc) · 1.78 KB
/
MachorroProject4.py
File metadata and controls
66 lines (60 loc) · 1.78 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Gary Machorro
#8/25/17
#Project 4:Lists and file input/output
from tkinter.filedialog import askopenfilename, asksaveasfilename
## gets the temperature and adds them to a list
# @return the temperature list
#
def getTemp():
stringTempList=[]
tempList=[]
infileName = askopenfilename()
infile = open(infileName, "r")
for line in infile:
line=line.split()
stringTempList=stringTempList+line
for i in range(len(stringTempList)):
temp=float(stringTempList[i])
tempList.append(temp)
return tempList
infile.close()
## gets the highest value in the list
# @param tempList the list of values
# @return the highest value
def getHighest(tempList):
highest=max(tempList)
return highest
## gets the lowest value in the list
# @param tempList the list of values
# @return the lowest value
def getLowest(tempList):
lowest=min(tempList)
return lowest
## gets the average value in the list
# @param tempList the list of values
# @return the average value
def getAverage(tempList):
tempSum=sum(tempList)
listLength=len(tempList)
tempAvg=tempSum/listLength
return tempAvg
##
#This program allows the user to choose input and output file to compute
#the max,min,and average
#
def main():
tempList=getTemp()
highest=str(getHighest(tempList))
lowest=str(getLowest(tempList))
average=round(getAverage(tempList),2)
tempAvg=str(average)
outfileName = asksaveasfilename()
outfile = open(outfileName, "w")
outfile.write("highest temperature:")
outfile.write(highest)
outfile.write("\nlowest temperature:")
outfile.write(lowest)
outfile.write("\naverage temperature:")
outfile.write(tempAvg)
outfile.close()
main()