Grading tool - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Grading tool (/thread-14135.html) |
Grading tool - Stuffed_crust - Nov-16-2018 so im trying to complete an assignment and i need to figure out how to get all the grades that are below 60 out of a list of grades the user submits. so far this is what i have def getGrade(): list = [] numOfGrades = int(input("please enter how many grades you will be entering: ")) for i in range(numOfGrades): grades = int(input("please enter a grade: ")) list.append(grades) return numOfGrades, list def validategrade(grades): if grades > 100 or grades < 0: print("one or more of the grades you entered is wrong please try again") getGrade() def max(list): return max(list) def min(list): return min(list) def calculateAverage(sum, numOfGrades): return sum/numOfGrades def displayAll(classAvg): print("The class average is", round(classAvg, 1)) RE: Grading tool - Larz60+ - Nov-16-2018 this code can be simplified. There's no need to ask for the number of grades being entered as this can be found simply: Rule, never name a variable, functu=ion, class, etc. using a python symbol (list is bad choice) simplify getGrade: def getGrade(): grade_list = [] while True grade = input(please a grade, or -1 to quit: ) if grade < 0: break gread_list.append(grade) return grade_listchange: def calculateAverage(sum, numOfGrades): return sum/numOfGradesto: def calculateAverage(grade_list): return sum(grade_list)/len(grade_list)to purge grade_list of grades < 60, clue: for i in reversed(grade_list): ... RE: Grading tool - stullis - Nov-16-2018 You should remove these two functions: def max(list): return max(list) def min(list): return min(list)Since they merely pass their arguments to another function, they aren't adding any value. Plus, they will likely cause errors and infinite recursion because they're either calling themselves (which calls themselves, which calls themselves, ...) or due to an ambiguous name since the functions max() and min() already exist. |