NEP -OS lAB B.Sc

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 . . .
DOWNLOAD PDF FILE OS LAB MANUAL

4.

 
  
 
 4.Write a python program to get information about power-supply.
import psutil

def get_power_info():
    # Get power status
    power_status = psutil.sensors_battery()

    if power_status is None:
        print("Power status: Running on ac power   .")
    else:
        percent = power_status.percent
        power_plugged = power_status.power_plugged
        seconds_left = power_status.secsleft

        if power_plugged:
            power_plugged_str = "Plugged in"
        else:
            power_plugged_str = "Not plugged in"

        print("Battery percentage:", percent)
        print("Power status:", power_plugged_str)
        if seconds_left is not None:
            print("Time left (seconds):", seconds_left)
        else:
            print("Time left: Unknown")

if __name__ == "__main__":
     get_power_info()


Output 4:
Power status: Running on ac power   .


( on laptop)
Battery percentage : 90%
Power status : Plugged in