Skip to content

Commit 05e1912

Browse files
AkshajV1309pre-commit-ci[bot]cclauss
authored
Create norgate.py (TheAlgorithms#7133)
* Create norgate.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Create norgate.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update boolean_algebra/norgate.py * Update boolean_algebra/norgate.py * Update boolean_algebra/norgate.py * Update boolean_algebra/norgate.py * Update boolean_algebra/norgate.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 3deb4a3 commit 05e1912

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

boolean_algebra/norgate.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
""" A NOR Gate is a logic gate in boolean algebra which results to false(0)
2+
if any of the input is 1, and True(1) if both the inputs are 0.
3+
Following is the truth table of an NOR Gate:
4+
| Input 1 | Input 2 | Output |
5+
| 0 | 0 | 1 |
6+
| 0 | 1 | 0 |
7+
| 1 | 0 | 0 |
8+
| 1 | 1 | 0 |
9+
"""
10+
"""Following is the code implementation of the NOR Gate"""
11+
12+
13+
def nor_gate(input_1: int, input_2: int) -> int:
14+
"""
15+
>>> nor_gate(0, 0)
16+
1
17+
>>> nor_gate(0, 1)
18+
0
19+
>>> nor_gate(1, 0)
20+
0
21+
>>> nor_gate(1, 1)
22+
0
23+
>>> nor_gate(0.0, 0.0)
24+
1
25+
>>> nor_gate(0, -7)
26+
0
27+
"""
28+
return int(bool(input_1 == input_2 == 0))
29+
30+
31+
def main() -> None:
32+
print("Truth Table of NOR Gate:")
33+
print("| Input 1 |", " Input 2 |", " Output |")
34+
print("| 0 |", " 0 | ", nor_gate(0, 0), " |")
35+
print("| 0 |", " 1 | ", nor_gate(0, 1), " |")
36+
print("| 1 |", " 0 | ", nor_gate(1, 0), " |")
37+
print("| 1 |", " 1 | ", nor_gate(1, 1), " |")
38+
39+
40+
if __name__ == "__main__":
41+
import doctest
42+
43+
doctest.testmod()
44+
main()
45+
"""Code provided by Akshaj Vishwanathan"""
46+
"""Reference: https://www.geeksforgeeks.org/logic-gates-in-python/"""

0 commit comments

Comments
 (0)