Python Program To Shutdown Windows Desktop

The execution of a computer program controls every digital device you use. Programs are a set of instructions given to a system for performing specific operations. Also, programs help the hardware and software to interact with each other. And with the help of these programs, you can also control your desktop environment. If you know basic programming, then giving instructions to your desktop with the use of pre-written programs might make you seem more extraordinary in front of your friends. So today, we’re going to start with a straightforward Python Program To Shutdown Windows Desktop.

 

What’s The Approach?

 

  • Firstly we are going to import the os library.

 

  • Now, we’ll take the input in a variable, with yes and no as the options.

 

  • If the user selects no as the option, we’ll execute the exit() function.

 

  • However, if the user selects yes as the option, we’ll execute the command,  os.system("shutdown /s /t 1")

 

Also Read: Implement Radix Sort Using Python

 

Python Program To Shutdown Windows Desktop

 

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

 

Ethix

I'm a coding geek interested in cyberspace who loves to write and read

Leave a Reply

Your email address will not be published. Required fields are marked *