933 points
8 4 2


Hello Kodlogs,
I want to make a Python program that will ask the user for a restart or end the program itself. I googled a bit to get an idea for this type of execution and gather some pieces of information. After researching a bit understand, I need to import the OS module from the library. How can I proceed further? Could you please help me in this regard? I am expecting your answers. Thanks.


Well, as far as you are asking for a self-restart program, you can try the below program:

import os
print("Hello World!")
result = input("\nDo you want to restart the program? [y/n] > ")
if result == 'y':
     os.system('python "C:/Users/Desktop/Folder/"')
     print("\nThe program will be closed...")

This will print an Output of “Hello World!” and then ask the user for the confirmation to proceed on or not! Pressing the ‘Y’ yes will execute the path file from the desired folder else the program will be closed immediately. Please, have a close look at the above program and let me know if you still have any confusion.

Thanks and good luck!

More Posts

How to do powers in python Naymul01 - Oct 5
How do windows know which program to use to open a file when you double click it? Farkhanda Athar - Aug 30, 2020
Shutdown command options in Windows :: shutdown /r /f /t 0 mhfaisal - Jun 1
what does return do in python? Naymul01 - Oct 15
Python program to convert celsius to fahrenheit and vice versa Tasnia Sultana - Sep 2
How to reverse a list in python using for loop? Naymul01 - Oct 19
How to set a timer in python ? Naymul01 - Oct 19
How to get the first character of a string in python? Naymul01 - Oct 19
How to sort a text file in python? Naymul01 - Oct 17
How to iterate through a list in python Naymul01 - Oct 14