How to Create a Python Program to Schedule Computer Shutdown
How to Create a Python Program to Schedule Computer Shutdown
Institute Name: PEARL INSTITUTE BATALA
In this tutorial, we will learn how to create a Python program with a basic user interface that allows users to schedule a computer shutdown time. By following the instructions below, you’ll be able to create a simple application that automates the process of shutting down your computer at a specified time.
Code:
# Importing the necessary libraries
import os
import time
# Function to schedule computer shutdown
def schedule_shutdown():
print("Enter the time in seconds to schedule shutdown:")
time_input = int(input())
# Delay the shutdown
time.sleep(time_input)
# Shut down the computer
os.system("shutdown /s /t 1")
# Calling the function to schedule shutdown
schedule_shutdown()
Instructions:
- Open your preferred Python IDE or text editor.
- Create a new Python file and paste the above code into it.
- Save the file with a .py extension (e.g., shutdown.py).
Running the Program:
- Open the command prompt or terminal.
- Navigate to the directory where you saved the shutdown.py file.
- Run the program by typing
python shutdown.py
and pressing Enter.
Post Comment