6つのテスト名とそのスコアを入力し、tests.txtという名前のテキストファイルに書き込むプロンプトを表示する必要があります。私はループを使用する必要があり、各入力はファイル内の独自の行に書き込まれる必要があります。完了すると、プログラムは確認メッセージを生成する必要があります。Python 3.5 - テキストファイルを生成する
サンプル出力
Entering six tests and scores
Enter test name objects
Enter % score on this test 88
Enter test name loops
Enter % score on this test 95
Enter test name selections.
Enter % score on this test 86
Enter test name variables
Enter % score on this test 82
Enter test name files
Enter % score on this test 100
Enter test name functions
Enter % score on this test 80
File was created successfully
は、その後、私は読んで、前のプログラムからtests.txtを処理するためにループを使用して別のプログラムを書く必要があります。プログラムは、テスト名とスコアを示す2列のテーブルを出力する必要があります。表が完成したら、小数点以下1桁まで正確に表示する必要があります。
サンプル出力
Reading six tests and scores
TEST SCORE
objects 88
loops 95
selections 86
variables 82
files 100
functions 80
Average is 88.5
これは、これまでと私がしなければならなかったものを超えています。これまでのところ、私の仕事はとても簡単でした。私はPython 3.5を使用しているので、私は新しい関数を使うことはできません。これまでのところ、私はtxtのドキュメントを生成するための最初のプログラムのためにこれを持っている
:PROGRESS WITH
EDIT(メイン
def main():
myfile = open('test.txt', 'w')
test = input('Please enter test name or enter to quit ')
while test != '':
score = int(input('Enter % score on this test '))
myfile.write(test + '\n')
myfile.write(str(score) + '\n')
test = input('Please enter test name or enter to quit ')
myfile.close()
print('File was created successfully')
)を
、第2のプログラムは次のようになりますし、おおよその形状です:
def main():
f = open('test.txt', 'r');
text = f.read();
f.close()
メイン()
誰かが私にある方向を教えてくれますか?ありがとう!
'f'は通常何を意味しますか?私は以前にそれを使用する必要はなかった。 –
@GoldDial 'f'は単なる変数名です...ここで' f'を使って 'file'(あるいはむしろ' _io.TextIOWrapper')を表します。 – HyperNeutrino