Grade Classifier - Problem

You are building a grading system for a school. Given a student's numerical score (0-100), you need to assign the corresponding letter grade based on the standard grading scale.

Grading Scale:

  • A: 90-100
  • B: 80-89
  • C: 70-79
  • D: 60-69
  • F: 0-59

Your task is to write a function that takes a numerical score and returns the appropriate letter grade as a string.

Input & Output

Example 1 — Excellent Grade
$ Input: score = 92
Output: A
💡 Note: Score 92 is >= 90, so it falls in the A grade range (90-100)
Example 2 — Good Grade
$ Input: score = 85
Output: B
💡 Note: Score 85 is >= 80 but < 90, so it gets grade B (80-89)
Example 3 — Failing Grade
$ Input: score = 45
Output: F
💡 Note: Score 45 is < 60, so it receives the failing grade F

Constraints

  • 0 ≤ score ≤ 100
  • Score is always an integer

Visualization

Tap to expand
INPUTStudent Score85Range: 0-100Integer valueALGORITHM1Check if score ≥ 90 → A2Else if score ≥ 80 → B3Else if score ≥ 70 → C4Early exit when matched85 ≥ 90? NO85 ≥ 80? YES → Grade BRESULTLetter GradeBScore 85 → Grade B(Range: 80-89)Key Insight:Use if-else ladder starting from highest grade (A) and work downward.This enables early termination - stop checking once a condition matches!TutorialsPoint - Grade Classifier | If-Else Ladder Approach
Asked in
Amazon 15 Microsoft 12 Google 8
12.5K Views
High Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen