Bird
0
0

Given two variables a and b, which Ruby expression returns true only if a is less than b and both are not equal?

hard📝 Application Q9 of 15
Ruby - Operators and Expressions
Given two variables a and b, which Ruby expression returns true only if a is less than b and both are not equal?
Aa < b
Ba <= b
Ca > b
Da == b
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the meaning of a < b

    The operator '<' means strictly less than, so a < b is true only if a is less than b and not equal.
  2. Step 2: Eliminate incorrect options

    a <= b ('a <= b') returns true when a equals b. a > b ('a > b') checks greater than, wrong direction. a == b checks equality, which is false for less than.
  3. Final Answer:

    a < b -> Option A
  4. Quick Check:

    '<' means less than and not equal [OK]
Quick Trick: '<' means strictly less than, no need for extra checks [OK]
Common Mistakes:
MISTAKES
  • Using <= which includes equality
  • Confusing < with <= or ==

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes