-
Notifications
You must be signed in to change notification settings - Fork 0
/
レベルアップ問題集Python3 論理演算メニュー
66 lines (51 loc) · 1.18 KB
/
レベルアップ問題集Python3 論理演算メニュー
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<論理演算を用いた計算のまとめ>
step1 論理積 AND の基本
# utf-8
a, b = map(int, input().split())
print(a and b)
step2 論理和 OR の基本
# utf-8
a, b = map(int, input().split())
print(a or b)
step3 否定 NOT の基本
# utf-8
a = int(input())
print(int(not a))
step4 排他的論理和 XOR の基本
# utf-8
a, b = map(int, input().split())
print(a ^ b)
step5 NAND 演算の基本
# utf-8
a, b = map(int, input().split())
print(int(not (a and b)))
step6 NOR 演算の基本
# utf-8
a, b = map(int, input().split())
print(int(not (a or b)))
step7 XNOR 演算の基本
# utf-8
a, b = map(int, input().split())
print(int(not (a ^ b)))
step8 半加算器
# utf-8
a, b = map(int, input().split())
c = a & b
s = a ^ b
print(c, s)
step9 全加算器
# utf-8
a, b, c1 = map(int, input().split())
# 半加算器のプログラム
def halfAdder(a, b):
c = a & b
s = a ^ b
return (c, s)
cx, sy = halfAdder(a, b)
cy, s = halfAdder(sy, c1)
c2 = cx ^ cy
print(c2, s)
final 論理演算を用いた計算のまとめ
# utf-8
a, b, c, d = map(int, input().split())
print(int(not((not (a) and not (b)) or not (c)) ^ d))