Advertisement
DeaD_EyE

calculate_grade

Jun 29th, 2020
1,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def calculate_grade(score, maximum=100):
  2.     """
  3.    This function returns the grade of score.
  4.    
  5.    score := score in points
  6.    maximum := maximum possible score
  7.  
  8.    The score are normalized internally to 100.
  9.    """
  10.  
  11.     score /= maximum
  12.     score *= 100
  13.     print(score)
  14.     grades_100 = {
  15.         93: "A", 90: "A-",
  16.         87: "B+", 83: "B", 80: "B-",
  17.         77: "C+", 73: "C", 70: "C-",
  18.         67: "D+", 63: "D", 60: "D-",
  19.         }
  20.     for min_score, grade in grades_100.items():
  21.         if score >= min_score:
  22.             return grade
  23.     else:
  24.         return "F"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement