Bird
0
0

Analyze this Ruby code:

hard📝 Application Q9 of 15
Ruby - Variables and Data Types
Analyze this Ruby code:
def sum_values
  amount = 50
  Amount = 100
  amount += Amount
  puts amount
end
sum_values

What will be the output?
A150
B50
CError
D100
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable types and operations

    amount is a local variable (lowercase), Amount is a constant (uppercase).
  2. Step 2: Evaluate the expression

    amount += Amount means amount = amount + Amount -> 50 + 100 = 150.
  3. Step 3: Output

    The puts prints 150.
  4. Final Answer:

    150 -> Option A
  5. Quick Check:

    Local variable updated by adding constant [OK]
Quick Trick: Local vars and constants are distinct; addition works normally [OK]
Common Mistakes:
  • Confusing constants with local variables
  • Expecting an error due to case difference
  • Ignoring that constants can be used in expressions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes