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

質問編集履歴

1

説明文を入れました。

2020/07/03 16:59

投稿

Chibichan
Chibichan

スコア72

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に書き込みたいのですが、一番最後の回文のみ書き込まれます。すべての回文を書き込むには、どのようにコードを入れたらいいでしょうか。