Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Python Script to Shutdown Computer

  • Difficulty Level : Basic
  • Last Updated : 14 Jul, 2019

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 library in the ide. If you don’t have it, then ‘pip install os‘ through the Command Prompt.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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 –

import os
shutdown = input("Do you wish to shutdown your computer ? (yes / no): ")
if shutdown == 'no':
    os.system("shutdown /s /t 1")

Organized Folder

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :