Learn to Code by Solving Problems: A Python Programming Primer Homepage for the book Learn to Code by Solving Problems: A Python Programming Primer

Finding a Bug

It looks like my code has a glitch.
I’m not really sure where it is.
I check pairs of flavors
with good count behavior.
Does anyone know what’s the sitch?

The problem that we’re trying to solve is Icecream.

Make sure you’ve read through Chapter 9 of Learn to Code by Solving Problems.

Here’s the code that doesn’t quite work:

lst = input().split()
n = int(lst[0])
m = int(lst[1])

bad_pairings = set()

for i in range(m):
    lst = input().split()
    tup = (int(lst[0]), int(lst[1]))
    bad_pairings.add(tup)

total_choices = 0

# Triple nested for loops to consider all triples of flavors
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        for k in range(j + 1, n + 1):
            # Three possible bad pairings to watch out for
            if ((i, j) not in bad_pairings and (i, k) not in bad_pairings and
                    (j, k) not in bad_pairings):
                total_choices = total_choices + 1

print(total_choices)

Thank you. Have a great day :)!