Ruby grammar problem . I don't know how to solve it [closed]












0















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.










share|improve this 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
















0















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.










share|improve this 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer





















  • 1





    to_i is needed

    – Santhosh
    Jan 2 at 5:54













  • @Santhosh Updated. Thanks :)

    – Tiw
    Jan 2 at 6:00

















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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.






share|improve this answer





















  • 1





    to_i is needed

    – Santhosh
    Jan 2 at 5:54













  • @Santhosh Updated. Thanks :)

    – Tiw
    Jan 2 at 6:00
















1














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.






share|improve this answer





















  • 1





    to_i is needed

    – Santhosh
    Jan 2 at 5:54













  • @Santhosh Updated. Thanks :)

    – Tiw
    Jan 2 at 6:00














1












1








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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





Popular posts from this blog

MongoDB - Not Authorized To Execute Command

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

How to fix TextFormField cause rebuild widget in Flutter