Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q5 of 15
Ruby - Variables and Data Types
What will be the output of this Ruby code?
num1 = 9
num2 = 4.0
result = num1 / num2
puts result
A2.25
B2
C2.0
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand division with mixed types

    Dividing an Integer by a Float returns a Float result.
  2. Step 2: Calculate the division

    9 divided by 4.0 equals 2.25 as a float.
  3. Final Answer:

    2.25 -> Option A
  4. Quick Check:

    Integer / Float yields Float result [OK]
Quick Trick: Integer divided by Float returns Float [OK]
Common Mistakes:
MISTAKES
  • Assuming integer division truncates result
  • Expecting integer output when dividing by float
  • Confusing 2.0 with 2.25

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes