私はクラスの数学スコアの平均を求めようとしていますが、私は辞書内でこれをどうやって行うのか分かりません。どのように私は各スコアを追加し、これを学生数(num_students)で割った簡単な方法を使用しますか?Dictionary in Python
login="teacher"
password="school"
usrnm=input("Please enter your username: ")
pw=input("Please enter your password: ")
if (usrnm==login) and (pw==password):
print("==Welcome to the Mathematics Score Entry Program==")
num_students = int(input("Please enter number of students:"))
print ("you entered ",num_students," students")
student_info = {}
student_data = ['Maths Score: ']
for i in range(0,num_students):
student_name = input("Name :")
student_info[student_name] = {}
for entry in student_data:
student_info[student_name][entry] = int(input(entry))
print (student_info)
else:
print("No way, Jose!")
それは把握することができるが、あなたがデータを見て期待のサンプルが含まれて本当に参考になりますあなたの質問のように。 –
通常は、入出力から*入出力を分離することをお勧めします。ですから、入力として辞書を取り、平均を返しますが、すべてのやりとりがない関数を書くべきです。 –
あなたの投稿を破壊しないでください。質問を投稿したら、(CC-by-SAライセンスのもとで)大規模なスタックオーバーフローコミュニティにコンテンツのライセンスを取得しました。この投稿とアカウントとの関連付けを解除する場合は、[解約リクエストの適切なルートは何ですか]を参照してください(http://meta.stackoverflow.com/questions/323395/what-is-the-proper-route-解離要求のために)。 – Bugs