0
0
Rubyprogramming~20 mins

Arithmetic operators in Ruby - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Arithmetic Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of mixed arithmetic operations
What is the output of this Ruby code?
Ruby
result = 10 + 5 * 2 - 8 / 4
puts result
A24
B18
C14
D12
Attempts:
2 left
💡 Hint
Remember the order of operations: multiplication and division happen before addition and subtraction.
Predict Output
intermediate
2:00remaining
Integer division vs float division
What will this Ruby code print?
Ruby
a = 7 / 2
b = 7 / 2.0
puts a
puts b
A
3.5
3
B
3
3
C
3
3.5
D
3.5
3.5
Attempts:
2 left
💡 Hint
Division with integers truncates the decimal part, but with floats it keeps it.
🔧 Debug
advanced
2:00remaining
Identify the error in arithmetic expression
What error does this Ruby code raise?
Ruby
x = 5 + * 3
puts x
ASyntaxError
BTypeError
CNoMethodError
DZeroDivisionError
Attempts:
2 left
💡 Hint
Look carefully at the operator usage between numbers.
Predict Output
advanced
2:00remaining
Modulo operator behavior
What is the output of this Ruby code?
Ruby
puts -13 % 5
A2
B-3
C-2
D3
Attempts:
2 left
💡 Hint
Modulo in Ruby always returns a non-negative remainder when the divisor is positive.
🧠 Conceptual
expert
2:00remaining
Result of chained assignment with arithmetic
What is the value of variable 'a' after running this Ruby code?
Ruby
a = b = 10
b += 5
c = a + b
A5
B15
C25
D10
Attempts:
2 left
💡 Hint
Remember that 'a' and 'b' are assigned independently and changing 'b' after does not affect 'a'.