標題:
407 字串與檔案處理 (字元刪除及另存新檔)
[打印本頁]
作者:
鄭繼威
時間:
2024-2-1 09:20
標題:
407 字串與檔案處理 (字元刪除及另存新檔)
1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。
2. 設計說明:
請撰寫一程式,讀取read.txt檔案內容,將檔案中的「*」符號全部刪除,並寫入至write.txt檔案。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。
3. 輸入輸出:
輸入說明
讀取read.txt檔案內容
輸出說明
寫入至write.txt檔案
範例輸入
範例輸出
附件:
read.txt
本帖隱藏的內容需要回復才可以瀏覽
Python
with open(r'read.txt', 'r') as infile, open(r'write.txt', 'w') as outfile:
data = infile.read()
data = data.replace("*", "")
outfile.write(data)
複製代碼
作者:
陳羨芮
時間:
2024-2-1 13:59
with open(r'read (1).txt', 'r') as r:
s=r.readline()
out=""
for i in range(len(s)):
if s[i]!="*":
out=out+s[i]
with open(r'write.txt','w') as w:
w.write(out)
複製代碼
作者:
鄭傳諭
時間:
2024-2-1 14:00
out=""
with open ("read.txt",'r')as r:
s=r.readline()
for i in range(len(s)):
if s[i]!='*':
out+=s[i]
with open ("write.txt",'w')as w:
w.write(out)
複製代碼
作者:
張桔熙
時間:
2024-2-1 14:00
out=""
with open("read.text",'r')as r:
s=r.readline()
for i in range(len(s)):
if s[i]!='*':
out+=s[i]
with open("write.txt",'w')as w:
w.write(out)
複製代碼
作者:
許浩浩
時間:
2024-2-1 14:04
with open(r'read.txt','r') as r:
s=r.readline()
out=""
for i in range(len(s)):
if(s[i]!='*'):
out+=s[i]
with open(r'write.txt','w') as w:
w.write(out)
複製代碼
作者:
沈敬翔
時間:
2024-2-1 14:05
本帖最後由 沈敬翔 於 2024-2-1 14:06 編輯
ans=""
with open('read.txt','r')as infile:
data=infile.readline()
for i in range(len(data)):
if data[i]!='*':
ans+=data[i]
with open('write.txt','w')as outfile:
outfile.write(ans)
複製代碼
回復
1#
鄭繼威
作者:
王亭婷
時間:
2024-2-1 14:06
out=""
with open('read.txt','r') as r:
s=r.readline()
for i in range(len(s)):
if s[i]!='*':
out+=s[i]
with open('write.txt','w') as w:
w.write(out)
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2