Five Beginner-Level Python Logic Puzzles

Rate this post

For my new book “Python Brain Games” (to appear in 2019, follow my email training program to get updates), I’m experimenting with a new code puzzle type: logics puzzles and brain games. It’s like Sudoku for coders! ??

Can you solve these five puzzles in five minutes? You can find the solutions at the end of this article…

# Puzzle 0
a, b, c, d = True, False, False, True

if not a or not c:
    print('yes')
else: 
    print('python')

What’s the output of this logic puzzle?

# Puzzle 1
a, b, c, d = False, True, False, False

if not d and b and d:
    if not a and not b:
        print('yes')
    elif a and c:
        print('yes')
    print('yes')
elif b:
    if d:
        print('love')
    print('python')
else: 
    print('python')

What’s the output of this logic puzzle?

# Puzzle 2
a, b, c, d = False, True, True, True

out = any([
    c or b and not d,
    a and b or c or not b,
    b and d and a or c,
    d and not d or b or a,
    not c,
    not b or b,
    a,
])

print(out)

What’s the output of this logic puzzle?

# Puzzle 3
a, b = False, True

out = (a and b and not a) or (not b) or (b and a) or (a and not a and not b)
print(out)

What’s the output of this logic puzzle?

# Puzzle 4
a, b, c = True, True, True

if b or not a or a:
    print('love')
else: 
    print('python')

What’s the output of this logic puzzle?

The Puzzle Solutions

# OUTPUT 0: 
'''
yes
'''

# OUTPUT 1: 
'''
python
'''

# OUTPUT 2: 
'''
True
'''

# OUTPUT 3: 
'''
False
'''

# OUTPUT 4: 
'''
love
'''

What percentage of puzzles could you solve correctly? 80% or above is advanced intermediate level.

Leave a Comment