Diego Sosa
Diego Sosa

Reputation: 1

Produce a truth table set of n values, but I have only one problem

def make_tt_ins(n):
   if n == 0:
      return []
   elif n == 1:
      return [False, True]
   else:
      prev_set = make_tt_ins(n - 1)
      full_set = cross_multiply(prev_set, [False, True])
      return full_set

def cross_multiply(s1, s2):
   rtn_set = []
   for i in range(len(s1)):
      for j in range(len(s2)):
         if type(s1[i]) == bool:
            nxt = [s1[i], s2[j]]
            rtn_set.append(nxt)
         else:
            nxt = []
            for x in range(len(s1[i])):
               nxt.append(s1[i][x])
               nxt.append(s2[j])
            rtn_set.append(nxt)
   return rtn_set

The above code is something that I've been able to make in python language. The point of this function is to return a list of the truth table given a number of values(n). ex. [[False, False], [False, True], [True, False], [True, True]] if n=2. This all works out perfectly fine for me, but when I am going to turn it in for my project, apparently calling make_tt_ins(n) with n=1, I get a "TypeError: 'bool object is not iterable", however when n is any other value, it works out just fine and without a problem. I even tested it before and after with n=1 and I still don't get an issue. I was wondering if anyone can help me understand what this is happening!

Upvotes: 0

Views: 241

Answers (0)

Related Questions