Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the logical NAND of two variables in Python

I'm making a function that makes 50 random trees in a 1000 by 1000 area.

I need to make sure that Tree 2's x and y both are not the same as Tree 1's x and y. This takes a NAND Gate. I'm okay with one of them being the same, I'm okay with neither being the same, but not with both being the same. I can't seem to find anything about making NAND Gates in python. I'm fine with defining a function to make a NAND.

like image 424
Jonathan Spirit Avatar asked Dec 17 '13 17:12

Jonathan Spirit


People also ask

How do you write NAND in Python?

NAND Gate. The 'NAND' gate is a combination of 'AND' gate followed by 'NOT' gate. Opposite to 'AND' gate, it provides an output of 0 only when both the bits are set, otherwise 1. In Python, 'NAND()' function can be implemented using the 'AND()' and 'OR()' functions created before.

How do you use multiple logical operators in Python?

To evaluate complex scenarios we combine several conditions in the same if statement. Python has two logical operators for that. The and operator returns True when the condition on its left and the one on its right are both True . If one or both are False , then their combination is False too.

What is NAND logic gate?

What is a NAND gate? A two-input NAND gate is a digital combination logic circuit that performs the logical inverse of an AND gate. While an AND gate outputs a logical “1” only if both inputs are logical “1,” a NAND gate outputs a logical “0” for this same combination of inputs.


1 Answers

Since NAND is the negation of and,

not (a and b) 

should totally work, with a and b as inputs, or do I miss something?

like image 95
jcklie Avatar answered Nov 02 '22 22:11

jcklie