質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

1347閲覧

python初心者:エラーの訂正方法を教えてください。

kashio

総合スコア12

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2020/01/03 09:03

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.

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2020/01/03 09:14

インデントが判りませんので、コードは「コードの挿入」で記入してください。
shiracamus

2020/01/03 09:15

コードブロックは ```言語名 で改行してください。 ```python ここにコードを書く ```
y_waiwai

2020/01/03 09:44

このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
退会済みユーザー

退会済みユーザー

2020/01/03 11:52

Pythonにおけるインデントは他の言語のカッコくらい強力な力があります。このエラーもインデントが原因で起きているかもしれません。 皆様がご指摘のように ```python3 open_file = open('point.txt') raw_date = open_file.read() (略) ``` のように再編集ください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問