+ 7

How to print a message before taking user input in Ruby on Decoder/VS Code/Ruby Mine??

When I run my program, it asks for user input before printing any message. I want my Program to print the message before asking user input. I didn't run my program on SL. I made the program on pc and decoder!!

2nd Sep 2020, 11:00 AM
Reca Resu
Reca Resu - avatar
15 Answers
+ 11
def prompt(*args) print(*args) gets end num = prompt "Input number: " puts num
2nd Sep 2020, 12:46 PM
Vladimir (temporary inactive)
Vladimir (temporary inactive) - avatar
+ 6
it properly works in RubyMine: Input number: 10 10 Process finished with exit code 0
2nd Sep 2020, 4:29 PM
Vladimir (temporary inactive)
Vladimir (temporary inactive) - avatar
+ 5
Såñtösh Màràvi I am definitely sure that this problem is not there in Python, C and Java (in any IDE) So, pls confirm before saying that
2nd Sep 2020, 12:11 PM
Namit Jain
Namit Jain - avatar
+ 5
Såñtösh Màràvi MSN👑 Kindly read the question carefully before answering It is clearly written "I have not used SL"
2nd Sep 2020, 12:12 PM
Namit Jain
Namit Jain - avatar
+ 5
it properly works in irb console: irb irb(main):001:1* def prompt(*args) irb(main):002:1* print(*args) irb(main):003:1* gets irb(main):004:0> end => :prompt irb(main):005:0> irb(main):006:0> num = prompt "Input number: " Input number: 10 irb(main):007:0> irb(main):008:0> puts num 10 => nil irb(main):009:0>
2nd Sep 2020, 4:33 PM
Vladimir (temporary inactive)
Vladimir (temporary inactive) - avatar
+ 4
Namit Jain ok I understood
2nd Sep 2020, 12:22 PM
Sâñtôsh
Sâñtôsh - avatar
+ 3
It's not only in Ruby, it's also in Python ,C languages & java . Here no message before printing in sololearn . Here sololearn give its give your input here.
2nd Sep 2020, 11:07 AM
Sâñtôsh
Sâñtôsh - avatar
+ 3
Såñtösh Màràvi I didn't make the program here bcz I know SL editor. Read above I have mentioned that
2nd Sep 2020, 11:09 AM
Reca Resu
Reca Resu - avatar
+ 3
SoloLearn doesn't have an interactive console. So it won't print any msg before taking input.
2nd Sep 2020, 11:19 AM
MSN
MSN - avatar
+ 3
Vladimir I tried this but still it asks for input first. Output: 5 Input number: 5
2nd Sep 2020, 1:46 PM
Reca Resu
Reca Resu - avatar
+ 2
MSN👑 please read my question's description I didn't made that Program on sololearn editor
2nd Sep 2020, 11:24 AM
Reca Resu
Reca Resu - avatar
+ 2
Ɗeⱥᖙpͥooͣlͫツ When u hit the run button in SoloLearn code playground and if any input is required then it prompts the user for input first. So I think there's no way to print any msg before input. Happy coding!
2nd Sep 2020, 11:28 AM
MSN
MSN - avatar
+ 1
@MSN👑 I have told you already that I didn't make my program on SL
2nd Sep 2020, 11:34 AM
Reca Resu
Reca Resu - avatar
+ 1
RKK doesn't work
2nd Sep 2020, 11:42 AM
Reca Resu
Reca Resu - avatar
0
try something like this: puts "Please enter a number: " inp = gets puts inp
2nd Sep 2020, 11:41 AM
minirkk
minirkk - avatar