Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 925 Bytes

File metadata and controls

38 lines (29 loc) · 925 Bytes

Python Project: Shutdown and Restart Computer 🐍

Python Script
This repo contains python code that shuts down or turns off your computer depending on your input.
Type 'r' to restart or 's' to shut down.

import os
import platform

def shutdown():
    if platform.system() == "Windows":
        os.system('shutdown -s')
    elif platform.system() == "Linux" or platform.system() == "Darwin":
        os.system("shutdown -h now")
    else:
        print("Os not supported!")

def restart():
    if platform.system() == "Windows":
        os.system("shutdown -t 0 -r -f")
    elif platform.system() == "Linux" or platform.system() == "Darwin":
        os.system('reboot now')
    else:
        print("Os not supported!")


command = input("Use \'r\' for restart and \'s\' for shutdown: ").lower()

if command == "r":
    restart()
elif command == "s":
    shutdown()
else:
    print("Wrong letter")