这是我的程序的剪辑
import os.path
#define global variables
database = []#list to store monthly temperatures
DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
WEEKS = 6
此函数从文本文件中读取输入并将数据添加到 列表称为数据库。数据值作为字符串添加。 每周的数据是列表中的一行。
def getInputFromFile(filename = None):
result = False
if(filename == None):
filename = input("Enter name of input file: ")
if(os.path.isfile(filename)):
infile = open(filename, 'r')
count = 0
for line in infile:
week = line.strip()
weekList = week.split()
database.append(weekList)
count += 1
infile.close()
return True
else:
print("Invalid filename ... aborting ...")
return False
'''
This function creates and returns a list with seven values,
each one being a day average for that month.
'''
def getWeekAverages():
pass
weekAverages = []
MAX = WEEKS
## total = 0
for week in range (WEEKS):
total = 0
for day in range(len(DAYS)):
total += int(database[week][day])
weekAverages.append(total/7)
return weekAverages
def getDayAverages():
pass
dayAverages = []
MAX = WEEKS
for day in range(len(DAYS)):
total = 0
for week in range (WEEKS):
total += int(database[week][day])
dayAverages.append(total/WEEKS)
return dayAverages
def getHighestDayAverage(dayAverages):
return max(dayAverages)
## Lowest day average
def getLowestDayAverage(dayAverages):
return min(dayAverages)
在我的def main中一切正常。它拉动文件并进行所有计算......现在我必须将这个程序编写成类...需要一些帮助。