回答編集履歴

1

コードの改善

2021/08/23 13:14

投稿

kazuma-s
kazuma-s

スコア8224

test CHANGED
@@ -8,17 +8,11 @@
8
8
 
9
9
  def decision():
10
10
 
11
- number = []
12
-
13
- leng = []
11
+ data = []
14
12
 
15
13
  for i in range(4):
16
14
 
17
- s = input("Enter in a " + str(i+3) + " digit password (numbers only): ")
15
+ data.append(input("Enter in a " + str(i+3) + " digit password (numbers only): "))
18
-
19
- number.append(int(s))
20
-
21
- leng.append(len(s))
22
16
 
23
17
 
24
18
 
@@ -28,7 +22,11 @@
28
22
 
29
23
  result = []
30
24
 
31
- for j in range(4):
25
+ for s in data:
26
+
27
+ number = int(s)
28
+
29
+ leng = len(s)
32
30
 
33
31
  counts = []
34
32
 
@@ -36,9 +34,9 @@
36
34
 
37
35
  guess = count = 0
38
36
 
39
- while guess != number[j]:
37
+ while guess != number:
40
38
 
41
- guess = random.randint(10**(leng[j]-1),(10**leng[j]-1))
39
+ guess = random.randint(10**(leng-1),(10**leng-1))
42
40
 
43
41
  count += 1
44
42
 
@@ -62,6 +60,8 @@
62
60
 
63
61
  decision()
64
62
 
63
+
64
+
65
65
  ```
66
66
 
67
67
  希望通りの簡略化でなくてすみませんが、このコードについてコメントをお願いします。