Every single code project that you will touch in your career will contain control flow statements such as while and if. A control flow statement requires Boolean logic to determine the program’s execution.
Basics of Boolean Logic
The basics of Boolean logic are simple.
β₯οΈ Info: Are you AI curious but you still have to create real impactful projects? Join our official AI builder club on Skool (only $5): SHIP! - One Project Per Month
- 1) The expression
x and yisTrue, if bothxandyareTrue. - 2) The expression
x or yisTrue, if at least one of the two variables isTrue. - 3) The expression
not xisTrue, if x isFalse. - 4) The expression
a and b or cis the same as(a and b) or cmeaning that “and” evaluates before “or”.
These four rules are enough to solve the following puzzle about Boolean operators: Can you solve it?
Puzzle Boolean Logic
I scraped this puzzle’s data from Reddit’s most influential users:
# Influential reddit users
# in million karmas
way_fairer = 2.7
StickleyMan = 2.3
_vargas_ = 2.3
smeeee = 1.3
a = way_fairer > StickleyMan
b = StickleyMan < smeeee and a c = _vargas_ >= StickleyMan
c = a and b or c and smeeee > 1.2
d = not ((a and b) or c)
if c and a:
print(d)
else:
print(not d)Puzzle: What is the output of this code snippet?
A good puzzle trains one aspect of your coding skills. This puzzle improves an important skill: understanding basic logical operators.
Are you a master coder? You can check out the solution to this puzzle here:
Test your skills now!