Daily Python Puzzle: Basics of Boolean Logic

What is the output of this code snippet?


# 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(not d) 

A good puzzle trains one aspect of your coding skills. This puzzle improves an important skill: understanding basic logical operators.

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.

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 puzzle.

Are you a master coder?
Test your skills now!

Related Video




Leave a Comment