dimanche 22 mars 2020

If not... followed by function

I am stuck with this question. I am not too concerned about what each function does, but more importantly how does the IF statement work with functions. From my understanding, the IF.... or statements usually work with a condition, but for this scenario it only involves two functions without any conditions?

def disk_check_usage(disk):
    du = shutil.disk_usage(disk)
    free = du.free/du.total * 100
    return free > 20 

def check_cpu_usage():
    usage = psutil.cpu_percent(1)
    return usage < 75 


if not disk_check_usage("/") or not check_cpu_usage():
    print("ERROR!")
else: 
    print("Everything is OK")

I want it to give an 'Error!' message when both conditions (free > 20 and usage < 75) are not True/Satisfied.

Edit: When I run the code, 'free' = 17 which gives 'False' and Usage < 75 which gives 'True'. So my IF statement would mean 'If not False or not True:'. What does that mean and how does the system whether to run 'if' or 'else' statement?

Any help will be appreciated!

Aucun commentaire:

Enregistrer un commentaire