DEV Community

Discussion on: Daily Challenge #68 - Grade Book

Collapse
colorfusion profile image
Melvin Yeo

I wrote this in Python with the assumption that the input of the function will all be integers between 0 and 100.

def grade(*grades):
    grade_range = [(90, 'A'),(80, 'B'),(70, 'C'),(60, 'D')]
    mean = 0

    for _, score in enumerate(grades):
        mean += score

    mean = int(mean / len(grades))

    polarity = "+" if mean % 10 >= 5 else "-"

    for grade in grade_range:
        if mean >= grade[0]:
            return grade[1] + polarity

    return "F" + polarity