Popcorn Hack 1
var = True
var1 = False
if var:
print("The variable is true!")
else:
print("The variable is false!")
if var1:
print("The 2nd variable is false!")
else:
print("The 2nd variable is true!")
if var and var1:
print("The variable is true but the 2nd variable is false.")
elif var or var1:
print("Either variable is true or false.")
The variable is true!
The 2nd variable is true!
Either variable is true or false.
Popcorn Hack 2
x = int(input("Enter an integer: "))
if x > 10:
print("The number is greater than 10!")
elif x < 10:
print("The number is less than 10!")
else:
print("The number is equal to 10!")
Popcorn Hack 3
x = int(input("Enter an integer: "))
if x>=100 and x<=999:
print("Your integer is a 3-digit number!")
else:
print("Your number isn't a 3-digit integer!")
Homework Hack
import itertools
variables = ['A', 'B']
truth_values = [True, False]
truth_table = list(itertools.product(truth_values, repeat=len(variables)))
print(" | ".join(variables) + " | NOT (A AND B) | NOT A OR NOT B")
print("-" * (len(variables) * 4 + 30))
for values in truth_table:
A, B = values
output1 = not (A and B)
output2 = (not A) or (not B)
print(f"{A!s:>5} | {B!s:>5} | {output1!s:>13} | {output2!s:>13}")
A | B | NOT (A AND B) | NOT A OR NOT B
--------------------------------------
True | True | False | False
True | False | True | True
False | True | True | True
False | False | True | True