1
1
from __future__ import annotations
2
2
3
+ from typing import Sequence
4
+
3
5
4
6
def compare_string(string1: str, string2: str) -> str:
5
7
"""
@@ -9,17 +11,17 @@ def compare_string(string1: str, string2: str) -> str:
9
11
>>> compare_string('0110','1101')
10
12
'X'
11
13
"""
12
- l1 = list(string1)
13
- l2 = list(string2)
14
+ list1 = list(string1)
15
+ list2 = list(string2)
14
16
count = 0
15
- for i in range(len(l1 )):
16
- if l1 [i] != l2 [i]:
17
+ for i in range(len(list1 )):
18
+ if list1 [i] != list2 [i]:
17
19
count += 1
18
- l1 [i] = "_"
20
+ list1 [i] = "_"
19
21
if count > 1:
20
22
return "X"
21
23
else:
22
- return "".join(l1 )
24
+ return "".join(list1 )
23
25
24
26
25
27
def check(binary: list[str]) -> list[str]:
@@ -28,7 +30,7 @@ def check(binary: list[str]) -> list[str]:
28
30
['0.00.01.5']
29
31
"""
30
32
pi = []
31
- while 1 :
33
+ while True :
32
34
check1 = ["$"] * len(binary)
33
35
temp = []
34
36
for i in range(len(binary)):
@@ -46,19 +48,18 @@ def check(binary: list[str]) -> list[str]:
46
48
binary = list(set(temp))
47
49
48
50
49
- def decimal_to_binary(no_of_variable: int, minterms: list [float]) -> list[str]:
51
+ def decimal_to_binary(no_of_variable: int, minterms: Sequence [float]) -> list[str]:
50
52
"""
51
53
>>> decimal_to_binary(3,[1.5])
52
54
['0.00.01.5']
53
55
"""
54
56
temp = []
55
- s = ""
56
- for m in minterms:
57
+ for minterm in minterms:
58
+ string = ""
57
59
for i in range(no_of_variable):
58
- s = str(m % 2) + s
59
- m //= 2
60
- temp.append(s)
61
- s = ""
60
+ string = str(minterm % 2) + string
61
+ minterm //= 2
62
+ temp.append(string)
62
63
return temp
63
64
64
65
@@ -70,16 +71,13 @@ def is_for_table(string1: str, string2: str, count: int) -> bool:
70
71
>>> is_for_table('01_','001',1)
71
72
False
72
73
"""
73
- l1 = list(string1)
74
- l2 = list(string2)
74
+ list1 = list(string1)
75
+ list2 = list(string2)
75
76
count_n = 0
76
- for i in range(len(l1 )):
77
- if l1 [i] != l2 [i]:
77
+ for i in range(len(list1 )):
78
+ if list1 [i] != list2 [i]:
78
79
count_n += 1
79
- if count_n == count:
80
- return True
81
- else:
82
- return False
80
+ return count_n == count
83
81
84
82
85
83
def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]:
@@ -108,7 +106,7 @@ def selection(chart: list[list[int]], prime_implicants: list[str]) -> list[str]:
108
106
for k in range(len(chart)):
109
107
chart[k][j] = 0
110
108
temp.append(prime_implicants[i])
111
- while 1 :
109
+ while True :
112
110
max_n = 0
113
111
rem = -1
114
112
count_n = 0
0 commit comments