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
if score >= 90
  puts "Grade A"
elsif score >= 80
  puts "Grade B"
elsif score >= 70
  puts "Grade C"
else
  puts "Grade F"
end
AGrade A
BGrade B
CGrade F
DGrade C
Step-by-Step Solution
Solution:
  1. Step 1: Check conditions in order

    score is 75. First condition: score >= 90 is false. Second: score >= 80 is false. Third: score >= 70 is true.
  2. Step 2: Output for first true condition

    Since third condition is true, it prints "Grade C" and skips the rest.
  3. Final Answer:

    Grade C -> Option D
  4. Quick Check:

    75 >= 70 is true, so output is Grade C [OK]
Quick Trick: Check conditions top to bottom; first true runs [OK]
Common Mistakes:
  • Choosing Grade B or A without checking order
  • Ignoring that only first true condition runs
  • Confusing >= with >

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes