How to take two variables as input by user, in one line with space? | Sololearn: Learn to code for FREE!
+ 1

How to take two variables as input by user, in one line with space?

I want to to take two variables input by user in one line with space. Ex. Input: 22 48 output: 22 48=70 Please help me. Thanks

4th Apr 2017, 12:26 PM
Abhishek Kumar
Abhishek Kumar - avatar
5 Answers
+ 6
Tried doing it, I got a No Output at first I'll reply back when I found a way
5th Apr 2017, 1:38 PM
MrCoder
MrCoder - avatar
+ 5
in python, you could split the string into a list. I dont know if this is possible in ruby though...
5th Apr 2017, 1:51 PM
Supersebi3
Supersebi3 - avatar
+ 5
@Huan Wang Doing good today :D Thanks, Its summer today so I dont have school anymore, code day everyday :D
5th Apr 2017, 11:05 PM
MrCoder
MrCoder - avatar
+ 2
I give you a simple way: puts "Please input some numbers: " x = gets.chomp.split(" ") puts x.inject(0) {|sum, ele| sum += ele.to_i} You can input as many numbers as you want, enjoy!
5th Apr 2017, 2:07 PM
Steven Wang
Steven Wang - avatar
+ 2
@MrCoder, how are you these days?
5th Apr 2017, 2:10 PM
Steven Wang
Steven Wang - avatar