Read three bits and print the outputs of five three-input gates.
Input
One line with three bits, a, b and c (each 0 or 1).
Output
Five lines, in this order and format: AND x, OR x, XOR x, NAND x, NOR x. A three-input XOR is 1 when an odd number of its inputs are 1.
Examples
Example 1 · Input
0 1 1
Expected output
AND 0 OR 1 XOR 0 NAND 1 NOR 0
Example 2 · Input
1 1 1
Expected output
AND 1 OR 1 XOR 1 NAND 0 NOR 0
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Use & for AND, | for OR and ^ for XOR, with all three bits: a & b & c.
Hint 2
NAND is 1 - (a & b & c), NOR is 1 - (a | b | c).
Hint 3
XOR of three bits is 1 when an odd number of them are 1.
Solution
Show one correct solution (try it yourself first)
a, b, c = map(int, input().split())
print("AND", a & b & c)
print("OR", a | b | c)
print("XOR", a ^ b ^ c)
print("NAND", 1 - (a & b & c))
print("NOR", 1 - (a | b | c))