How To Shutdown PC using Python
|ShutDown PC With Python|
Hey my geeky friend today I'm going to tell you something special & geeky. Today you are going to learn that how can you shutdown your PC just using few lines of python code, so without wasting time let's get started.
Here's the our simple python code to ShutDown PC immediately.
#asking from user
shutdown = input("Do You Want to ShutDown You PC ? (YES / NO): ")
#if user input is NO then
if shutdown == 'NO':
#if user input is YES then
os.system("shutdown /s /t 1")
Here in this code we had first import os library and used
os.system function with
shutdown /s /t 1 code actually its a shell command. . If you hadn't imported os system in your ide import it using command prompt. One more important thing this program would directly shutdown your PC within few seconds so please make sure you have saved and closed your all important programs and applications before executing this code.
Hope you had liked our article please share with your programmer friends and Follow us on social media to get updated with latest updates, tips and tricks for programmers and developers.