Skip to content

Commit 59c3c8b

Browse files
robohiepre-commit-ci[bot]MaximSmolskiy
authored
Add N Input AND Gate (#12717)
* Update and_gate.py J'ai nourri ce programme en ajoutant une porte And à n entrées. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update and_gate.py Commentaires en anglais * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update and_gate.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <[email protected]>
1 parent a728cc9 commit 59c3c8b

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

boolean_algebra/and_gate.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
2-
An AND Gate is a logic gate in boolean algebra which results to 1 (True) if both the
3-
inputs are 1, and 0 (False) otherwise.
2+
An AND Gate is a logic gate in boolean algebra which results to 1 (True) if all the
3+
inputs are 1 (True), and 0 (False) otherwise.
44
5-
Following is the truth table of an AND Gate:
5+
Following is the truth table of a Two Input AND Gate:
66
------------------------------
77
| Input 1 | Input 2 | Output |
88
------------------------------
@@ -12,7 +12,7 @@
1212
| 1 | 1 | 1 |
1313
------------------------------
1414
15-
Refer - https://www.geeksforgeeks.org/logic-gates-in-python/
15+
Refer - https://www.geeksforgeeks.org/logic-gates/
1616
"""
1717

1818

@@ -32,6 +32,18 @@ def and_gate(input_1: int, input_2: int) -> int:
3232
return int(input_1 and input_2)
3333

3434

35+
def n_input_and_gate(inputs: list[int]) -> int:
36+
"""
37+
Calculate AND of a list of input values
38+
39+
>>> n_input_and_gate([1, 0, 1, 1, 0])
40+
0
41+
>>> n_input_and_gate([1, 1, 1, 1, 1])
42+
1
43+
"""
44+
return int(all(inputs))
45+
46+
3547
if __name__ == "__main__":
3648
import doctest
3749

0 commit comments

Comments
 (0)