Basics of Boolean Logic: A Short Guide

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.

  • 1) The expression x and y is True, if both x and y are True.
  • 2) The expression x or y is True, if at least one of the two variables is True.
  • 3) The expression not x is True, if x is False.
  • 4) The expression a and b or c is the same as (a and b) or c meaning 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!

Leave a Comment