質問編集履歴
1
ptulos.txtへすべての回文を書き込みたいのですが…
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
-
```
|
1
|
+
```def paaohjelma(word):
|
2
|
-
while True:
|
2
|
+
while True:
|
3
|
-
|
3
|
+
word=tiedosto.readline().rstrip()
|
4
|
-
|
4
|
+
if word=="":
|
5
|
-
|
5
|
+
break
|
6
|
-
|
6
|
+
elif word==word[::-1]:
|
7
|
+
file=open("ptulos.txt","w",encoding="utf-8")
|
8
|
+
file.write(word) #ここに入れますと一番最後に出力された回文しかでません。
|
7
|
-
|
9
|
+
print("Rivi ","'",word.strip(),"'"," on palindromi.",sep='')
|
8
|
-
|
10
|
+
file.close()
|
9
|
-
print("Rivi ","'",word.strip(),"'"," ei ole palindoromi.",sep='')
|
10
|
-
|
11
|
+
elif word.isdigit():
|
11
|
-
|
12
|
+
print("Rivi ","'",word.strip(),"'"," on numerorivi.",sep='')
|
13
|
+
else:
|
14
|
+
print("Rivi ","'",word.strip(),"'"," ei ole palindromi.",sep='')
|
15
|
+
return
|
16
|
+
|
17
|
+
tiedosto=open("pmalli.txt","r",encoding="utf-8")
|
18
|
+
paaohjelma(tiedosto)
|
12
19
|
tiedosto.close()
|
13
20
|
|
14
|
-
```
|
21
|
+
```
|
15
|
-
ファイルを開けて、ファイル内にあるワードの回文判定をしますが、答えがすべて3番目のIF文(全部回文ではない)になってしまいます。4番目は、ワードが数字のみの場合は、数列で返します。
|
16
|
-
どこがまちがっていますでしょうか?
|
17
|
-
どうぞよろしくお願いいたします。
|