1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。
2. 設計說明:
請撰寫一程式,讓使用者輸入一個正整數,並讀取read.txt檔案內容,read.txt檔案中包含多列英文句子。若輸入值為n,則讀取n列read.txt檔案內容,將n列中的每個英文單字字首轉為大寫再輸出,並寫入至write.txt檔案。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。
3. 輸入輸出:
輸入說明
一個正整數n,並讀取read.txt檔案內容
輸出說明
將n列中的每個英文單字字首轉為大寫再輸出,並寫入至write.txt檔案
範例輸入
5

範例輸出
Hello World!
What Is The Weather Like Out There?
Are You Ok?
What's Today's Date?
Excuse Me!

附件:read.txt
本帖隱藏的內容需要回復才可以瀏覽
Python- f = open('read.txt','r')
- line = f.readlines()
- f.close()
- wf = open('write.txt','w')
- n = int(input())
- for i in line[:n]:
- i = i.strip()
- i = i.split(' ')
- for idx, word in enumerate(i):
- word = word.capitalize()
- if idx == len(i) - 1:
- print(word)
- wf.write(word + '\n')
- else:
- print(word, end = ' ')
- wf.write(word + ' ')
- # print(i)
- # wf.write(word+'\n')
- wf.clo
複製代碼 |