boolean-expression

Python Sympy – Select monomials from ANF of Boolean expression

Python Sympy – Select monomials from the ANF of a Boolean expression Question: I have some truth table in GF(2) and I compute the corresponding Algebraic Normal Form (ANF) or Zhegalkin polynomial. Below a dummy example with two variables. from sympy.logic.boolalg import ANFform from sympy.abc import x, y truth_table = [0, 1, 1, 1] expr …

Total answers: 1

Why is year 1900 not returning False?

Why is year 1900 not returning False? Question: def is_leap_year(year): if (year%4==0 & (year%100!=0)) | (year%4==0 & year%100==0 & year%400==0): return True else: return False print(is_leap_year(1900)) I would like for the argument (1900) to yield a False, since both sides of the or ( | ) statement fails to be true. What am I missing? …

Total answers: 1

How to find duplicates in a string

How to find duplicates in a string Question: I am working on creating a world game, and I do not want my game to accept duplicate input’s by the user, ex: ‘mirror’. I tried finding the duplicates one way but it didn’t work, and I do not know how to make my program realize that …

Total answers: 4

numpy vectorize if elif elif else

numpy vectorize if elif elif else Question: I have a function: def aspect_good(angle: float, planet1_good: bool, planet2_good: bool): """ Decides if the angle represents a good aspect. NOTE: returns None if the angle doesn’t represent an aspect. """ if 112 <= angle <= 128 or 52 <= angle <= 68: return True elif 174 <= …

Total answers: 1

CS50's Introduction to Artificial Intelligence with Python – Knowledge

CS50's Introduction to Artificial Intelligence with Python – Knowledge Question: I’m studyng Harvard’s Introduction to Artificial Intelligence with Python course. I’m enjoying a lot. However I downloaded logic file to use Boolean algebra and Knowledge, that simple operations (OR,AND,NOT…) Before I show my doubt I will share the Knowledge class from harvard source code, I …

Total answers: 1

Why does `if None.__eq__("a")` seem to evaluate to True (but not quite)?

Why does `if None.__eq__("a")` seem to evaluate to True (but not quite)? Question: If you execute the following statement in Python 3.7, it will (from my testing) print b: if None.__eq__(“a”): print(“b”) However, None.__eq__(“a”) evaluates to NotImplemented. Naturally, “a”.__eq__(“a”) evaluates to True, and “b”.__eq__(“a”) evaluates to False. I initially discovered this when testing the return …

Total answers: 4

What is Truthy and Falsy? How is it different from True and False?

What is Truthy and Falsy? How is it different from True and False? Question: I just learned there are truthy and falsy values in python which are different from the normal True and False. Can someone please explain in depth what truthy and falsy values are? Where should I use them? What is the difference …

Total answers: 8

'and' (boolean) vs '&' (bitwise) – Why difference in behavior with lists vs numpy arrays?

'and' (boolean) vs '&' (bitwise) – Why difference in behavior with lists vs numpy arrays? Question: What explains the difference in behavior of boolean and bitwise operations on lists vs NumPy arrays? I’m confused about the appropriate use of & vs and in Python, illustrated in the following examples. mylist1 = [True, True, True, False, …

Total answers: 8

Why does "a == x or y or z" always evaluate to True?

Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those? Question: I am writing a security system that denies access to unauthorized users. name = input("Hello. Please enter your name: ") if name == "Kevin" or "Jon" or "Inbar": print("Access granted.") else: print("Access …

Total answers: 8