open_file
1raw_date = open_file.read() 2open_file.close() 3point_data = raw_date.splitlines() 4 5point_dict = {} 6for line in point_data: 7 student_name, points_str = line.split(':') 8 point_dict[student_name] = points_str 9 10score_dict = {} 11for student_name in point_dict: 12 point_list = point_dict[student_name].split(',') 13 subject_number = len(point_list) 14 total = 0 15 for point in point_list: 16 total = total + int(point) 17 average = total / subject_number 18 score_dict[student_name] = (total,average,subject_number) 19 20evaluation_dict = {} 21for student_name in score_dict: 22 score_date = score_dict[student_name] 23 total = score_date[0] 24 average = score_date[1] 25 subject_number = score_date[2] 26 27 excellent = subject_number * 100 * 0.8 28 good = subject_number * 100 * 0.65 29 if total >= excellent: 30 evaluation = 'Excellent' 31 elif total >= good: 32 evaluation = 'Good' 33 else: 34 evaluation = 'Bad' 35 evaluation_dict[student_name] = evaluation 36 37file_name = 'evaluation.txt' 38output_file = open('file_name', 'w') 39for student_name in score_dict: 40 score_date = score_dict[student_name] 41 total = score_date[0] 42 43 evaluation = evaluation_dict[student_name] 44 45 text = '[{}]_total: {}, evaluation: {}\n'.format(student_name, total, evaluation) 46 output_file.write(text) 47 48 output_file.close() 49 print('評価結果を{}に出力しました'.format(file_name)) 50 51 52ここに言語を入力 53以下のエラーが表示されるのですが、原因がわかりません、ご教示いただけないでしょうか? 54 55評価結果をevaluation.txtに出力しました 56Traceback (most recent call last): 57 File "file.py", line 47, in <module> 58 output_file.write(text) 59ValueError: I/O operation on closed file.
このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
Pythonにおけるインデントは他の言語のカッコくらい強力な力があります。このエラーもインデントが原因で起きているかもしれません。
皆様がご指摘のように
```python3
open_file = open('point.txt')
raw_date = open_file.read()
(略)
```
のように再編集ください。
あなたの回答
tips
プレビュー