3.5 Popcorn Hacks
Mihir's Submission for Hacks from Lesson
Popcorn Hack 1
Check if a boolean is true and check if both conditions are true or either is true.
# Check if a boolean is true
def is_true(value):
return value == True
# Check if both conditions are true (AND)
def both_true(a, b):
return a and b
# Check if either condition is true (OR)
def either_true(a, b):
return a or b
# Example usage:
print(is_true(True)) # Output: True
print(both_true(True, False)) # Output: False
print(either_true(True, False)) # Output: True
True
False
True
Popcorn Hack 2
Create a boolean expression to check if a number is greater than 10.
def is_greater_than_10(number):
return number > 10
# Example usage:
print(is_greater_than_10(15)) # Output: True
print(is_greater_than_10(8)) # Output: False
True
False
Popcorn Hack 3
Create a boolean expression to check if a number is a three-digit number.
def is_three_digits(number):
return 100 <= number <= 999
# Example usage:
print(is_three_digits(150)) # Output: True
print(is_three_digits(99)) # Output: False
print(is_three_digits(1000)) # Output: False
True
False
False