Python Forum

Full Version: Grading tool
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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))
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_list
change:
def calculateAverage(sum, numOfGrades):
    return sum/numOfGrades
to:
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):
    ...
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.