How to Create a Python Program to Schedule Computer Shutdown

How to Create a Python Program to Schedule Computer Shutdown
Spread the love

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:

  1. Open your preferred Python IDE or text editor.
  2. Create a new Python file and paste the above code into it.
  3. Save the file with a .py extension (e.g., shutdown.py).

Running the Program:

  1. Open the command prompt or terminal.
  2. Navigate to the directory where you saved the shutdown.py file.
  3. Run the program by typing python shutdown.py and pressing Enter.

o input the relevant SEO tags in the appropriate fields.

Post Comment