高考申論題
107年
[資訊處理] 程式語言
第 二 題
以下是完整的 Python 程式碼,請說明此程式的詳細功能為何?(10 分)
import os.path
file1 = input("Input a file name: ")
file2 = input("Input the other file name: ")
while not os.path.isfile(file1):
print("The file does not exist!")
file1 = input("Input a file name again: ")
while os.path.isfile(file2):
answer = input("The file existed, Overwrite it? y/n? ")
if answer == 'n' or answer=='N':
file2 = input("Input a file name again: ")
else:
break
fileObject1 = open(file1, "r")
fileObject2 = open(file2, "w")
content = fileObject1.read()
fileObject2.write(content)
fileObject1.close()
fileObject2.close()
📝 此題為申論題
思路引導 VIP
- 模組化分析:將程式碼切分為「輸入與驗證」、「檔案開啟」、「內容傳輸」與「關閉檔案」四個階段。
- 關鍵函數識別:
🤖
AI 詳解
AI 專屬家教
【考點分析】
本題考查 Python 的基本檔案 I/O 操作、os.path 模組的應用以及迴圈邏輯控制。
【理論/法規依據】
▼ 還有更多解析內容