TheAlgorithms-Python

Форк
0
37 строк · 887.0 Байт
1
"""
2
A XOR Gate is a logic gate in boolean algebra which results to 1 (True) if only one of
3
the two inputs is 1, and 0 (False) if an even number of inputs are 1.
4
Following 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

14
Refer - https://www.geeksforgeeks.org/logic-gates-in-python/
15
"""
16

17

18
def xor_gate(input_1: int, input_2: int) -> int:
19
    """
20
    calculate xor of the input values
21

22
    >>> xor_gate(0, 0)
23
    0
24
    >>> xor_gate(0, 1)
25
    1
26
    >>> xor_gate(1, 0)
27
    1
28
    >>> xor_gate(1, 1)
29
    0
30
    """
31
    return (input_1, input_2).count(0) % 2
32

33

34
if __name__ == "__main__":
35
    import doctest
36

37
    doctest.testmod()
38

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.