This simple Python script aims to Shutdown or Restart the user's computer system, based on the choice entered by the user in the console. In order to achieve that utility, we will be using the os library and then the os.system( )
function
os
Library of Python only
On the console, type import os;
After opening the script in your Python IDE, execute the code so that you get the console output window. The program will give you 4 choices:
- Shutdown Computer Immediately
- Shutdown Computer after Given Time
- Restart Computer Immediately
- Restart Computer after Given Time
Selecting options 2 and 4 will require you to input the time in seconds after which you want to restart/shutdown your system. Default otherwise for choices 1 and 4 is set as zero seconds. Note:
Proceed to execeute the code only after ensuring that you have saved and closed all working documents otherwise you will lose the progress in unsaved documents after the restart/shutdown