如果没有该特定行,我的代码将无法工作。为什么?

My code does not work without that specific line. Why?

puts "Enter the first number"
num1 = Float(gets)

puts "Enter the second number"
num2 = Float(gets)

puts "Enter the operation"
op = gets
op = op.chomp # <--- THIS LINE!

case op 
when "+" then puts num1 + num2
when "-" then puts num1 - num2    
when "*" then puts num1 * num2    
when "/" then puts num1 / num2
end

输入“+”操作时,您按了两个键,+return。两者都产生一个字符,结果是 "+\n"。 (即 \n 是换行符)

chomp 删除换行符。