因此,在我所拥有的课程中,我会逐行地从不同列表中收集的信息创建一个列表,并且到目前为止已经顺利进行。 我的问题是,使用这个新制作的列表,我需要在同一个类中使用不同的方法,以便以结构化的方式打印列表的信息。 我不确定如何将新列表从一种方法转移到另一种方法,以便我可以开始打印过程。 在我的主程序中,利用字典(字符串值作为键,类对象作为值)来引用类方法,我有输入
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,但是一旦我能够利用方法中的列表,那部分就会很容易。
So in a class that I have, I create a list from information gathered in a different list line by line, and so far that has gone smoothly. My issue is that with this newly made list, I need to utilize a different method in the same class in order to print the list's information in a structured manner. I am unsure of exactly how to get the new list from one method to another so that I can begin the printing process. In my main program, that utilizes a dictionary (string value as key, class object as value) to refer to the class methods, I have the input of
playerDict[nameChoice].calc(basicList)
which takes me to the method for the given player, and then compiles the list. The two methods are as follows
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.'''So the list I need in the printInfo method is ratingList. In my main program, I have invoked the two separately, using playerDict[nameChoice].calc(basicList) and playerDict[nameChoice].printInfo(), but I need to find a way to get the ratingList into the printInfo method in order to print out the information in the list in the specified manner. How would I go about doing this? I dont have printInfo completed yet but that part will come easily once I am capable of utilizing the list in the method.
最满意答案
def printInfo(self, basicList): ratingList = self.calc(basicList) ...请注意, printInfo需要列表。
def printInfo(self, basicList): ratingList = self.calc(basicList) ...Note that printInfo needs the list as well.
更多推荐
发布评论