Ruby grammar problem . I don't know how to solve it [closed]
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
My code is:
input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]
puts a + b
But it's not working, please help.
ruby
closed as unclear what you're asking by anothermh, Lenin Raj Rajasekaran, Santhosh, Jörg W Mittag, Sebastian Palma Jan 2 at 10:12
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
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
My code is:
input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]
puts a + b
But it's not working, please help.
ruby
closed as unclear what you're asking by anothermh, Lenin Raj Rajasekaran, Santhosh, Jörg W Mittag, Sebastian Palma Jan 2 at 10:12
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39
add a comment |
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
My code is:
input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]
puts a + b
But it's not working, please help.
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
My code is:
input_lines = gets.chop
a = input_lines[0]
b = input_lines[1]
puts a + b
But it's not working, please help.
ruby
ruby
edited Jan 4 at 7:31


anothermh
3,31931733
3,31931733
asked Jan 2 at 1:24
user10358924
closed as unclear what you're asking by anothermh, Lenin Raj Rajasekaran, Santhosh, Jörg W Mittag, Sebastian Palma Jan 2 at 10:12
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as unclear what you're asking by anothermh, Lenin Raj Rajasekaran, Santhosh, Jörg W Mittag, Sebastian Palma Jan 2 at 10:12
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39
add a comment |
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39
add a comment |
1 Answer
1
active
oldest
votes
Add split
to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines
already changed to Integers.
1
to_i
is needed
– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Add split
to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines
already changed to Integers.
1
to_i
is needed
– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
add a comment |
Add split
to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines
already changed to Integers.
1
to_i
is needed
– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
add a comment |
Add split
to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines
already changed to Integers.
Add split
to the chopped gets would work:
input_lines = gets.chop.split
a = input_lines[0].to_i
b = input_lines[1].to_i
puts a + b
Try it.
Check String doc.
More DRY way to do it:
input_lines = gets.chop.split.map(&:to_i)
a,b = input_lines
puts a + b
In this case the numbers inside input_lines
already changed to Integers.
edited Jan 2 at 7:04
answered Jan 2 at 4:02


TiwTiw
4,11761630
4,11761630
1
to_i
is needed
– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
add a comment |
1
to_i
is needed
– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
1
1
to_i
is needed– Santhosh
Jan 2 at 5:54
to_i
is needed– Santhosh
Jan 2 at 5:54
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
@Santhosh Updated. Thanks :)
– Tiw
Jan 2 at 6:00
add a comment |
Your question is very unclear. You say that "you solve the problem", so why are you asking this question if the problem is solved?
– Jörg W Mittag
Jan 2 at 7:18
Also, so you say that you have a problem with Ruby's grammar, but I don't see any syntactical problems in your code.
– Jörg W Mittag
Jan 2 at 8:39