teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

変数代入追記

2020/06/26 10:33

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -33,5 +33,6 @@
33
33
  for character in text:
34
34
  index = NOCK.find(character)
35
35
  if index >= 0:
36
- print((index // 5 + 1, index % 5 + 1))
36
+ nockcode = (index // 5 + 1, index % 5 + 1)
37
+ print(nockcode)
37
38
  ```

4

for文に置き換えた処理を追記

2020/06/26 10:33

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -23,4 +23,15 @@
23
23
  ```text
24
24
  [(3, 5), (1, 1), (1, 3), (1, 3), (3, 2), (5, 5), (1, 2), (3, 4), (5, 4), (5, 3), (2, 4), (4, 4), (2, 3), (2, 1), (2, 4), (5, 2), (1, 5), (1, 4), (3, 4), (6, 1), (1, 5), (3, 3), (3, 1), (2, 4), (4, 1), (4, 5), (3, 4), (4, 2), (2, 5), (4, 5), (2, 2), (4, 3)]
25
25
  PACCMYBOXWITHFIVEDOZENLIQUORJUGS
26
+ ```
27
+
28
+ text2nock関数を for文にしてprintするとこうなります。
29
+
30
+ ```py
31
+ def text2nock(text):
32
+ text = text.replace('K', 'C')
33
+ for character in text:
34
+ index = NOCK.find(character)
35
+ if index >= 0:
36
+ print((index // 5 + 1, index % 5 + 1))
26
37
  ```

3

文言変更

2020/06/26 10:29

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -1,5 +1,6 @@
1
- まだ習っていない内包表記を使って、こんな感じとか?
1
+ まだ習っていないであろう内包表記を使うとこんな感じ
2
2
  リストも使っているので、習った範囲の文法で書き直す必要がありますが・・・
3
+ なんとなくヒントになれば幸いです。
3
4
 
4
5
  ```py
5
6
  NOCK = 'ABCDEFGHIJLMNOPQRSTU5VWXYZ'

2

説明追記

2020/06/25 17:23

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -1,4 +1,5 @@
1
- 内包表記を使って、こんな感じとか?
1
+ まだ習っていない内包表記を使って、こんな感じとか?
2
+ リストも使っているので、習った範囲の文法で書き直す必要がありますが・・・
2
3
 
3
4
  ```py
4
5
  NOCK = 'ABCDEFGHIJLMNOPQRSTU5VWXYZ'

1

関数省略

2020/06/25 17:22

投稿

shiracamus
shiracamus

スコア5406

answer CHANGED
@@ -3,11 +3,8 @@
3
3
  ```py
4
4
  NOCK = 'ABCDEFGHIJLMNOPQRSTU5VWXYZ'
5
5
 
6
- def nockcode(index):
7
- return (index // 5 + 1, index % 5 + 1)
8
-
9
6
  def text2nock(text):
10
- return [nockcode(index)
7
+ return [(index // 5 + 1, index % 5 + 1)
11
8
  for index in map(NOCK.find, text.replace('K', 'C'))
12
9
  if index >= 0]
13
10