Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import namedtuple
- Student = namedtuple("Student", ["Id", "names", "labs", "scores"])
- student_list = []
- def create_sheet():
- user_input = input("Do you want to add another student? (Y/N)\n")
- if(user_input == "Y"):
- stu_id = int(input("What's his/her ID?\n"))
- name = input("What's his/her name?\n")
- labs = int(input("What's his/her lab?\n"))
- score = int(input("What's his/her score?\n"))
- student = Student( stu_id , name, labs, score)
- student_list.append(student)
- print("\nCurrent spreadsheet:\n")
- print("{} {:>9} {:>9} {:>9}".format("ID", "NAME", "LAB", "SCORE"))
- for i in range(0, len(student_list)):
- print("{} {:>9} {:>9} {:>9}".format(student_list[i].Id, student_list[i].names, student_list[i].labs, student_list[i].scores ))
- print()
- elif(user_input == "N"):
- print()
- score = {}
- for i in range(0, len(student_list)):
- score_list = []
- if(student_list[i].labs not in score):
- score_list.append(student_list[i].scores)
- score[student_list[i].labs] = score_list
- elif(student_list[i].labs in score):
- score[student_list[i].labs].append(student_list[i].scores)
- for i,v in score.items():
- count = 0
- avg = 0
- for j in v:
- avg += j
- count += 1
- score[i] = avg/count
- score = sorted(score.items())
- score = dict(score)
- for i, v in score.items():
- print("The average score on Lab {} is {:.2f}".format(i, v))
- class_avg = 0
- for i in range(0, len(student_list)):
- class_avg += student_list[i].scores
- print("The average score of the class is {:.2f}".format(class_avg/len(student_list)))
- return user_input
- ans = create_sheet()
- while ans != "N":
- ans = create_sheet()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement