Saturday, November 22, 2025
HomeLanguagesPython Script to Restart Computer

Python Script to Restart Computer

As we know, Python is a popular scripting language because of its versatile features. In this article, we will write a Python script to restart a computer. Let’s start with how to restart the system with Python.

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.

Causion: Please ensure that you save and close all the program before running this code on the IDLE, as the below program will immediately restart your computer.

Below is the Python implementation –




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


Output:
Restart
Here is the Python Program which will ask the user to restart the computer providing the option of Yes or No. Also, when you type yes & then press the ENTER key, the system will be restart instantly.

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11930 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS