TheAlgorithms-Python
37 строк · 887.0 Байт
1"""
2A XOR Gate is a logic gate in boolean algebra which results to 1 (True) if only one of
3the two inputs is 1, and 0 (False) if an even number of inputs are 1.
4Following is the truth table of a XOR Gate:
5------------------------------
6| Input 1 | Input 2 | Output |
7------------------------------
8| 0 | 0 | 0 |
9| 0 | 1 | 1 |
10| 1 | 0 | 1 |
11| 1 | 1 | 0 |
12------------------------------
13
14Refer - https://www.geeksforgeeks.org/logic-gates-in-python/
15"""
16
17
18def xor_gate(input_1: int, input_2: int) -> int:
19"""
20calculate xor of the input values
21
22>>> xor_gate(0, 0)
230
24>>> xor_gate(0, 1)
251
26>>> xor_gate(1, 0)
271
28>>> xor_gate(1, 1)
290
30"""
31return (input_1, input_2).count(0) % 2
32
33
34if __name__ == "__main__":
35import doctest
36
37doctest.testmod()
38