質問編集履歴
1
修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
pythonでJANコードのチェックデジットを作成したい
|
test
CHANGED
@@ -73,3 +73,51 @@
|
|
73
73
|
IndexError: list index out of range
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
```python
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
jan = ['490148007010', '490220141199',"497185049303"]
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
for idx in range(0, len(jan)):
|
88
|
+
|
89
|
+
odd_d_sum = 0
|
90
|
+
|
91
|
+
even_d_sum = 0
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
for i in range(0,12):
|
96
|
+
|
97
|
+
if (i + 1) % 2 == 0: # 偶数桁
|
98
|
+
|
99
|
+
even_d_sum += int(jan[idx][i])
|
100
|
+
|
101
|
+
else: # 奇数桁
|
102
|
+
|
103
|
+
odd_d_sum += int(jan[idx][i])
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
d1 = int(str(3 * even_d_sum + odd_d_sum)[-1])
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
if d1 == 0:
|
112
|
+
|
113
|
+
c_digit = 0
|
114
|
+
|
115
|
+
else:
|
116
|
+
|
117
|
+
c_digit = 10 - d1
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
print(c_digit)
|
122
|
+
|
123
|
+
```
|