To solve this problem, we need to complete the function calculate_grade that returns the appropriate letter grade based on a given score. The grading scale follows standard academic conventions: A (90+), B (80-89), C (70-79), D (60-69), and F (below 60).
Approach
The function uses conditional statements (if-elif-else) to check the score against the grading thresholds. Since the conditions are evaluated in order, we can use simple greater-than-or-equal checks (since higher thresholds are checked first, lower thresholds will only be considered if higher ones are not met).
Solution Code
def calculate_grade(score):
if score >= 90:
return 'A'
elif score >= 80:
return 'B'
elif score >= 70:
return 'C'
elif score >= 60:
return 'D'
else:
return 'F'
Explanation
- A Grade: Scores ≥90 are assigned 'A'.
- B Grade: Scores ≥80 (but <90, since the first condition already checked for ≥90) are assigned 'B'.
- C Grade: Scores ≥70 (but <80) are assigned 'C'.
- D Grade: Scores ≥60 (but <70) are assigned 'D'.
- F Grade: Any score below 60 is assigned 'F'.
This approach efficiently determines the grade by leveraging the order of conditional checks, ensuring correctness and simplicity.
Answer: The completed function as shown above. The blanks should be filled with score >=80, score >=70, and score >=60 respectively. So the final code is the one provided.


作者声明:本文包含人工智能生成内容。