Ruby语法问题。我不知道怎么解决它

Ruby语法问题。我不知道怎么解决它,ruby,Ruby,我的代码是: Please output the number obtained by adding a and b. At the end of the line break, do not include extra characters, blank lines. expmple1 1 1 result1 2 expmple2 0 99 result2 99 但它不起作用,请帮助。将拆分添加到切碎的GET将起作用: input_lines = gets.chop a = inp

我的代码是:

Please output the number obtained by adding a and b.

At the end of the line break, do not include extra characters, blank lines.

expmple1
1 1

result1
2

expmple2
0 99

result2
99
但它不起作用,请帮助。

将拆分添加到切碎的GET将起作用:

input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]

puts a + b
试试看。 检查

更干燥的方法:

input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i

puts a + b

在这种情况下,输入行中的数字已更改为整数。

更改为ineeded@Santhosh更新。谢谢:你的问题很不清楚。你说你解决了问题,那么如果问题解决了,你为什么要问这个问题?同样,你说你对Ruby的语法有问题,但是我在你的代码中没有看到任何语法问题。
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines

puts a + b