当前位置: 动力学知识库 > 问答 > 编程问答 >

python - trying to get the function def getLowestTemp(): to work..it pulls up the highest temp...I already have that function working

问题描述:

#import statements

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

def getDayAverages():

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 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 getHighestDayAverages(dayAverages):

average = max(dayAverages)

return average

def getLowestDayAverages(dayAverages):

average = min(dayAverages)

return average

def getHighestWeekAverages(weekAverages):

average = max(weekAverages)

return average

def getLowestWeekAverages(weekAverages):

average = min(weekAverages)

return average

this works

def getHighestTemp():

highestTemp = int(database[0][0])

for week in range (WEEKS):

for day in range(len(DAYS)):

if highestTemp < int(database[week][day]):

highestTemp = int(database[week][day])

return highestTemp

here is where I am having problems: getLowestTemp

def getLowestTemp():

lowestTemp = int(database[0][0])

for week in range (WEEKS):

for day in range(len(DAYS)):

if lowestTemp < int(database[week][day]):

lowestTemp = int(database[week][day])

return lowestTemp

def main():

goodFile = getInputFromFile("julywilm.txt")

if(goodFile == True):

dayAverages = getDayAverages()

weekAverages = getWeekAverages()

highestDay = getHighestDayAverages(dayAverages)

lowestDay = getLowestDayAverages(dayAverages)

highestWeek = getHighestWeekAverages(weekAverages)

lowestWeek = getLowestWeekAverages(weekAverages)

highestTemp = getHighestTemp()

lowestTemp = getLowestTemp

print(dayAverages)

print(weekAverages)

dayIndex = dayAverages.index(highestDay)

print(DAYS[dayIndex], 'with',getHighestDayAverages(dayAverages))

dayIndex = dayAverages.index(lowestDay)

print(DAYS[dayIndex], 'with', getLowestDayAverages(dayAverages))

print(getHighestWeekAverages(weekAverages))

print(getLowestWeekAverages(weekAverages))

print(getHighestTemp())

print(getLowestTemp())

main()

here is the actual text file.

70 74 104 57 78 65 96

82 67 100 43 60 57 93

66 75 90 78 64 72 73

86 93 64 109 79 70 44

81 72 95 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000

July 2014 Wilmington North Carolina

网友答案:

In "if lowestTemp < int(database[week][day]):" your "<" should be an ">".

分享给朋友:
您可能感兴趣的文章:
随机阅读: