How can I run this code on my computer? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

How can I run this code on my computer?

I wrote this code: user_input=input("say \"hi\" to the bot") if user_input=="hi": print("\n\nYou: hi \n\n\'Bot\': Hello Master") I can write it in IDLE on my computer and then save it on my computer. So if I'm double clicking on it Command Promt opens and it says: 'Say "hi" to the bot'. The problem is that I don't know what I should type in so that it says: "You: hi Bot: Hello Master" (when I tried to just type "hi" and then hit Enter the 'cmd window' closed

10th Feb 2017, 9:56 PM
Vinr Ƅlfakyn
Vinr Ƅlfakyn - avatar
4 Respostas
+ 3
This is a result of a program running, then instantly closing. In the prompt, once all the code has been executes, it closes itself. So the code has been run, just so fast you can't see it. The solution? import time *Your code here time.sleep(5) This imports time, and utilises its sleep command. What this is telling python to do is wait 5 seconds, then run the next line. In this case, closing the prompt. When you run it with this code, it will print the bot's statement, wait 5 seconds, then close. Now you don't have to use superhuman powers to read it! Hope I helped :)
10th Feb 2017, 10:09 PM
Lelearner
+ 3
@Lelearner Thanks! that was really helpful! I didn't think about that.
10th Feb 2017, 10:13 PM
Vinr Ƅlfakyn
Vinr Ƅlfakyn - avatar
+ 2
You need to call os.system("pause") if you are using windows. Also you should be able to run module in the IDLE, this way you can avoid the extra snippet of code. The CMD window automatically closes, so its nothing wrong with your program.
10th Feb 2017, 10:08 PM
~Q~
~Q~ - avatar
+ 2
ok, thx
10th Feb 2017, 10:08 PM
Vinr Ƅlfakyn
Vinr Ƅlfakyn - avatar