Skip to content

Update and_gate #12717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions boolean_algebra/and_gate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
An AND Gate is a logic gate in boolean algebra which results to 1 (True) if both the
inputs are 1, and 0 (False) otherwise.
An AND Gate is a logic gate in boolean algebra which results to 1 (True) if all the
inputs are 1 (True), and 0 (False) otherwise.

Following is the truth table of an AND Gate:
Following is the truth table of a Two Input AND Gate:
------------------------------
| Input 1 | Input 2 | Output |
------------------------------
Expand All @@ -12,7 +12,7 @@
| 1 | 1 | 1 |
------------------------------

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


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


def n_input_and_gate(inputs: list[int]) -> int:
"""
Calculate AND of a list of input values

>>> n_input_and_gate([1, 0, 1, 1, 0])
0
>>> n_input_and_gate([1, 1, 1, 1, 1])
1
"""
return int(all(inputs))


if __name__ == "__main__":
import doctest

Expand Down