+ 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!!
15 Answers
+ 11
def prompt(*args)
print(*args)
gets
end
num = prompt "Input number: "
puts num
+ 6
it properly works in RubyMine:
Input number: 10
10
Process finished with exit code 0
+ 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
+ 5
Såñtösh Màràvi MSN👑
Kindly read the question carefully before answering
It is clearly written "I have not used SL"
+ 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>
+ 4
Namit Jain ok I understood
+ 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.
+ 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
+ 3
SoloLearn doesn't have an interactive console.
So it won't print any msg before taking input.
+ 3
Vladimir I tried this but still it asks for input first.
Output:
5
Input number: 5
+ 2
MSN👑 please read my question's description
I didn't made that Program on sololearn editor
+ 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!
+ 1
@MSN👑 I have told you already that I didn't make my program on SL
+ 1
RKK doesn't work
0
try something like this:
puts "Please enter a number: "
inp = gets
puts inp