Bird
0
0

Given price = 10 and tax_rate = 0.2, which code correctly outputs the total price including tax using interpolation?

hard📝 Application Q9 of 15
Ruby - Variables and Data Types
Given price = 10 and tax_rate = 0.2, which code correctly outputs the total price including tax using interpolation?
A"Total: #{price + price * tax_rate}"
B"Total: #{price + tax_rate}"
C"Total: price + price * tax_rate"
D"Total: #{price * tax_rate}"
Step-by-Step Solution
Solution:
  1. Step 1: Calculate total price including tax

    Total price = price + (price * tax_rate) = 10 + 2 = 12.
  2. Step 2: Check interpolation expressions

    "Total: #{price + price * tax_rate}" correctly calculates total inside #{ }. "Total: #{price + tax_rate}" adds price and tax_rate incorrectly. "Total: price + price * tax_rate" is a string literal. "Total: #{price * tax_rate}" shows only tax amount.
  3. Final Answer:

    "Total: #{price + price * tax_rate}" -> Option A
  4. Quick Check:

    Use expressions inside #{ } for calculations [OK]
Quick Trick: Put full calculation inside #{ } to show computed result [OK]
Common Mistakes:
  • Adding variables without correct math
  • Using string literals instead of interpolation
  • Showing partial calculation results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes