私は学生名で記入する辞書を作成する出欠ロガーを作成しようとしています。名前はクラスの出席データ(クラスに参加したかどうかに関係なく)を追加するリストです。私はこれまでデフォルト値を持つ辞書の項目を自動的に追加するpython
#! /bin/python3
#add student to dict
def add_student(_dict):
student=input('Add student :')
_dict[student]=[]
return _dict
#collect outcomes
def collector(student,_dict, outcome):
_dict[student].append(outcome)
return _dict
#counts target
def count(_dict,target):
for i in _dict:
# records total attendance names
attendance_stat = len(_dict[i])
# records total instances absent
freq_of_absence=_dict[i].count(target)
# records percentage of absence
perc_absence = float((freq_of_absence/attendance_stat)*100)
print(i,'DAYS ABSENT =',freq_of_absence)
print('TOTAL DAYS: ', i, attendance_stat)
print('PERCENTAGE OF ABSENCE:', i, str(round(perc_absence, 2))+'%')
#main function
def main():
#date=input('DATE: ')
outcomes=['Y','N']
student_names = {}
try:
totalstudents = int(input('NO. OF STUDENTS: '))
except ValueError:
print('input an integer')
totalstudents = int(input('NO. OF STUDENTS: '))
while len(student_names) < totalstudents:
add_student(student_names)
print(student_names)
i = 0
while i < totalstudents:
i = i + 1
target='Y'
student=str(input('student :'))
outcome=str(input('outcome :'))
collector(student,student_names,outcome)
count(student_names,target)
if __name__=='__main__':
main()
` below`コードが表示されているコードは、これまでのところうまく動作しますが、問題は、学生の数が多すぎる場合、入力にかかる時間は授業時間にで切断広範囲です。不在者の数は通常存在する数よりも少ないため、欠席した各選択肢に対して値Yを付加する欠席の辞書の生徒から選択することが可能であり、Nを残りのリストに追加することが可能である。
ありがとう、ありがとうございました。私は今生徒を追跡して、何も残さないようにすることができます。 –
ようこそ。それがあなたを助けたら解決策としてマークしてもらえますか? – user3030010