Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Control Flow

What will be the output of this Ruby code?

score = 75
case score
in 0..49 then puts "Fail"
in 50..79 then puts "Pass"
in 80..100 then puts "Excellent"
else puts "Invalid"
end
APass
BFail
CExcellent
DInvalid
Step-by-Step Solution
Solution:
  1. Step 1: Check which range includes 75

    75 is not in 0..49 but is in 50..79.
  2. Step 2: Match the corresponding output

    The code prints "Pass" when score is in 50..79.
  3. Final Answer:

    Pass -> Option A
  4. Quick Check:

    75 in 50..79 means output "Pass" [OK]
Quick Trick: Find which range includes the value, then pick that output [OK]
Common Mistakes:
  • Choosing "Fail" because 75 is greater than 49
  • Confusing inclusive and exclusive ranges
  • Ignoring the order of case branches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes