Popcorn Hacks

#1
def check_single_boolean(value):
    if value:
        return "The boolean is True."
    else:
        return "The boolean is False."


print(check_single_boolean(True))  
print(check_single_boolean(False)) 

#1
def check_booleans(value1, value2):
    if value1 and value2:
        return "Both booleans are True."
    elif value1 or value2:
        return "Either one of the booleans is True."
    else:
        return "Neither of the booleans is True."


print(check_booleans(True, True))   
print(check_booleans(True, False))  
print(check_booleans(False, False)) 

#2
def is_greater_than_10(number):
    return number > 10


print(is_greater_than_10(12))  
print(is_greater_than_10(8))   

#3
def is_three_digits(number):
    return 100 <= abs(number) <= 999


print(is_three_digits(123))  
print(is_three_digits(99))    
print(is_three_digits(-456))  
print(is_three_digits(-1000)) 


Homework Hack


def de_morgan_laws():
    print("P\tQ\tNOT (P AND Q)\tNOT P OR NOT Q\tNOT (P OR Q)\tNOT P AND NOT Q")
    print("----------------------------------------------------------------------")
    
    for p in [True, False]:
        for q in [True, False]:
            not_p_and_q = not (p and q)
            not_p_or_not_q = (not p) or (not q)
            not_p_or_q = not (p or q)
            not_p_and_not_q = (not p) and (not q)
            print(f"{p}\t{q}\t{not_p_and_q}\t\t{not_p_or_not_q}\t\t{not_p_or_q}\t\t{not_p_and_not_q}")

de_morgan_laws()