How to stop command prompt from closing in python?

前端 未结 3 939
时光说笑
时光说笑 2020-12-10 07:29

I am very new to python.. I used the code

x = input(\" Hey what is your name \" )       
print(\" Hey, \" + x)  
input(\" press close to exit \")
         


        
3条回答
  •  心在旅途
    2020-12-10 07:49

    That can be done with os module. Following is the simple code :

    import os
    os.system("pause")
    

    This will generate a pause and will ask user to press any key to continue.

    [edit: The above method works well for windows os. It seems to give problem with mac (as pointed by ihue, in comments). The thing is that "os" library is operating system specific and some commands might not work with one operating system like they work in another one.]

提交回复
热议问题