質問編集履歴
1
説明文を入れました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
elif word==word[::-1]:
|
7
7
|
file=open("ptulos.txt","w",encoding="utf-8")
|
8
8
|
print("Rivi ","'",word.strip(),"'"," on palindromi.",sep='')
|
9
|
-
file.write(word)
|
9
|
+
file.write(word)#ここに入れると最後の回文のみ書き込まれます
|
10
10
|
file.close()
|
11
11
|
elif word.isdigit():
|
12
12
|
print("Rivi ","'",word.strip(),"'"," on numerorivi.",sep='')
|
@@ -17,4 +17,5 @@
|
|
17
17
|
tiedosto=open("pmalli.txt","r",encoding="utf-8")
|
18
18
|
paaohjelma(tiedosto)
|
19
19
|
tiedosto.close()
|
20
|
-
```
|
20
|
+
```
|
21
|
+
ファイルを読み込み、回文のみを別ファイルptulos.txtに書き込みたいのですが、一番最後の回文のみ書き込まれます。すべての回文を書き込むには、どのようにコードを入れたらいいでしょうか。
|