+

Python script to log off the computer

Let`s start with how to log out using Python.

Note: For this to work, you have to import os library in the ide. If you don`t have it, then ` pip install os ` through the Command Prompt.

Causion: Please ensure that you save and close all the program before running this code on the IDLE, as the below program will immediately log out your computer.

Below is the Python implementation —

import os

 

logout = input ( "Do you wish to log out your computer? (yes / no):" )

 

if logout = =  `no` :

  exit ( )

else :

  os.system ( " shutdown -l " )

Output:

Here is a Python program that will ask the user to log out of the computer by providing a Yes or No option. Also, when you type yes and then press Enter, the system will be logged out instantly.

Get Solution for free from DataCamp guru