Menu
Coddy logo textTech

Recap - Grade Classifier

Part of the Logic & Flow section of Coddy's Ruby journey — lesson 42 of 56.

Combine multi-value case, ternary, and inline modifiers to classify exam scores in one short script.

challenge icon

Challenge

Medium

Read a comma-separated list of integer scores from input. For each score, print one line:

<score>: <letter> (<status>)

Where letter comes from a case on the score:

  • 90..100A
  • 80..89B
  • 70..79C
  • 60..69D
  • anything else → F

And status uses a ternary: passing when the score is at least 60, failing otherwise.

After the loop, print Top scorer: <score>: but only if the maximum score is 90 or higher (use an inline if).

For input 95,72,55,88, the output is:

95: A (passing)
72: C (passing)
55: F (failing)
88: B (passing)
Top scorer: 95

Try it yourself

scores = gets.chomp.split(",").map(&:to_i)

# TODO: for each score print "<n>: <letter> (<status>)"
# TODO: print "Top scorer: <max>" only if max >= 90

All lessons in Logic & Flow