As we know, Python is a popular scripting language because of its versatile features. In this article, we will write a Python script to shutdown a computer.
To shut down the computer/PC/laptop by using a Python script, you have to use the
os.system() function with the code “
shutdown /s /t 1” .
Note: For this to work, you have to import
os libraryin the ide. If you don’t have it, then ‘
pip install os‘ through the Command Prompt.
Causion: Please ensure that you save and close all the program before running this code on the IDLE, as the below program will immediately shut down your computer.
Below is the Python implementation –
Here is the Python Program which will ask the user to shut down the computer providing the option of Yes or No. Also, when you type yes & then press the ENTER key, the system will be shut down instantly.
- Python Script to Restart Computer
- Python Script to Logout Computer
- Python | Add Logging to a Python Script
- Competitive Coding Setup for C++ and Python in VS Code using Python Script
- Python script to open a Google Map location on clipboard
- Autorun a Python script on windows startup
- Python | Accepting Script Input
- Running Python script on GPU.
- Run python script from anywhere in linux
- Convert Python Script to .exe File
- Add a User in Linux using Python Script
- Deleting a User in Linux using Python Script
- Get Your System Information - Using Python Script
- Python script to change MAC address of Linux machine
- Create a Python Script Notifying to take a break
- Python script to get device vendor name from MAC Address
- Plot multiple separate graphs for same data from one Python script
- Python script to shows Laptop Battery Percentage
- Python Script to change name of a file to its timestamp
- Python Script to check PC last reboot time
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.