所以在我的一个类中,我从不同列表中收集的信息一行一行地创建一个列表,到目前为止进展顺利。我的问题是,对于这个新创建的列表,我需要在同一个类中使用不同的方法,以便以结构化的方式打印列表的信息。我不确定如何将新列表从一种方法转换到另一种方法,以便开始打印过程。在我的主程序中,它使用字典(字符串值作为键,类对象作为值)来引用类方法,我有
playerDict[nameChoice].calc(basicList)
它将我带到给定播放器的方法,然后编译列表。这两种方法如下
def calc(self, sublist):
'''calculate a passer rating for one sub-list year in the info list'''
ratingList = []
count = 0
for line in self.info:
C = ((((int(line[3]) / int(line[4]))*100) - 30)/20)
if C > 2.375:
C = 2.375
Y = (((int(line[5]) / int(line[4])) - 3) * .25)
if Y > 2.375:
Y = 2.375
T = (((int(line[6])) / int(line[4])) * 20)
if T > 2.375:
T = 2.375
I = 2.375 - ((int(line[7])/int(line[4])) * 25)
ratingtop = (C + Y + T + I)
ratingbot = 6
yearRating = float((ratingtop / ratingbot) * 100)
ratingList.append([self.info[count][0], self.info[count][2], yearRating])
print(ratingList)
count += 1
ratingList.sort()
print(ratingList)
print_ratings = self.printInfo
return ratingList
def printInfo(self):
'''print individual year information about this player including each years passer rating. The list should be in year order. Use calc to assist.'''
所以printInfo方法中需要的列表是ratingList。在我的主程序中,我使用playerDict[nameChoice].calc(basicList)
和playerDict[nameChoice].printInfo()
分别调用了这两个函数,但是我需要找到一种方法将ratingList放入printInfo方法中,以便以指定的方式打印列表中的信息。我该怎么做呢?我还没有完成打印信息,但这一部分将很容易来,一旦我能够利用的方法中的列表
注意
printInfo
也需要这个列表相关问题 更多 >
编程相关推荐