这是我第一次涉足计算机编程.我选择学习Ruby,我很享受它.但是,我有点困惑的是为什么答案在这段代码中输出不正确.
def addition_function
puts "Which numbers would you like to add?"
@n1 = gets.chomp
@n2 = gets.chomp
@n1 + @n2 == @answer
puts "The sum is... #{@answer}"
end
def subtraction_function
puts "Which numbers would you like to subtract?"
@n1 = gets.chomp.to_i
@n2 = gets.chomp.to_i
@n1 - @n2 == @answer
puts "The answer is... #{@answer}"
end
def multiplication_function
puts "Which numbers would you like to multiply?"
@n1 = gets.chomp
@n2 = gets.chomp
@n1 * @n2 == @answer
puts "The answer is... …Run Code Online (Sandbox Code Playgroud) ruby ×1