標題:
409 字串與檔案處理 (字串加密)
[打印本頁]
作者:
鄭繼威
時間:
2024-2-1 14:29
標題:
409 字串與檔案處理 (字串加密)
1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。
2. 設計說明:
請撰寫一程式,讀取read.txt檔案內容,將檔案中的小寫英文字母加密,加密方法為所有小寫字母向後偏移2個字母,並將結果寫入至write.txt檔案。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。
3. 輸入輸出:
輸入說明
讀取read.txt檔案內容
輸出說明
寫入至write.txt檔案
範例輸入
範例輸出
附件:
read.txt
本帖隱藏的內容需要回復才可以瀏覽
python
f = open('read.txt','r')
line = f.read()
f.close()
wf = open('write.txt','w')
for i in line:
if i == 'y':
wf.write('a')
elif i == 'z':
wf.write('b')
else:
wf.write(chr(ord(i)+2))
wf.close()
複製代碼
作者:
許浩浩
時間:
2024-2-1 15:02
with open("read.txt",'r') as r:
out=""
s=r.readline()
for i in range(len(s)):
out+=chr(ord(s[i])+2)
with open("write.txt",'w') as w:
w.write(out)
複製代碼
作者:
沈敬翔
時間:
2024-2-1 15:05
out=""
with open('read.txt','r')as a:
n=a.read()
for i in range(len(n)):
out+=chr(ord(n[i])+2)
with open('write.txt','w')as b:
b.write(out)
複製代碼
回復
1#
鄭繼威
作者:
王亭婷
時間:
2024-2-1 15:09
out=""
with open("read (4).txt","r") as r:
s=r.readline()
for i in range(len(s)):
out+=chr(ord(s[i])+2)
with open("write.txt", "w") as w:
w.write(out)
作者:
陳羨芮
時間:
2024-2-1 15:13
out=""
with open(r'read (2).txt','r') as r:
str1=r.readline()
for i in range(len(str1)):
str2=ord(str1[i])+2
str3=chr(str2)
out+=str3
with open(r'write.txt','w') as w:
w.write(out)
複製代碼
作者:
鄭傳諭
時間:
2024-2-1 15:14
out=""
with open("read.txt",'r') as r:
s=r.readline()
for i in range(len(s)):
out+=chr(ord(s[i])+2)
with open("write.txt",'w') as w:
w.write(out)
複製代碼
作者:
張桔熙
時間:
2024-2-1 15:14
out=""
with open("read.txt",'r') as r:
s=r.readline()
for i in range(len(s)):
out+=chr(ord(s[i])+2)
with open("write.txt",'w') as w:
w.write(out)
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2