Advertisement
Rew35

5.15

Feb 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. from collections import namedtuple
  2.  
  3. Student = namedtuple("Student", ["Id", "names", "labs", "scores"])
  4. student_list = []
  5. def create_sheet():
  6. user_input = input("Do you want to add another student? (Y/N)\n")
  7. if(user_input == "Y"):
  8. stu_id = int(input("What's his/her ID?\n"))
  9. name = input("What's his/her name?\n")
  10. labs = int(input("What's his/her lab?\n"))
  11. score = int(input("What's his/her score?\n"))
  12. student = Student( stu_id , name, labs, score)
  13. student_list.append(student)
  14. print("\nCurrent spreadsheet:\n")
  15. print("{} {:>9} {:>9} {:>9}".format("ID", "NAME", "LAB", "SCORE"))
  16. for i in range(0, len(student_list)):
  17. print("{} {:>9} {:>9} {:>9}".format(student_list[i].Id, student_list[i].names, student_list[i].labs, student_list[i].scores ))
  18. print()
  19.  
  20. elif(user_input == "N"):
  21. print()
  22. score = {}
  23. for i in range(0, len(student_list)):
  24. score_list = []
  25. if(student_list[i].labs not in score):
  26. score_list.append(student_list[i].scores)
  27. score[student_list[i].labs] = score_list
  28. elif(student_list[i].labs in score):
  29. score[student_list[i].labs].append(student_list[i].scores)
  30. for i,v in score.items():
  31. count = 0
  32. avg = 0
  33. for j in v:
  34. avg += j
  35. count += 1
  36. score[i] = avg/count
  37.  
  38. score = sorted(score.items())
  39. score = dict(score)
  40. for i, v in score.items():
  41. print("The average score on Lab {} is {:.2f}".format(i, v))
  42.  
  43. class_avg = 0
  44. for i in range(0, len(student_list)):
  45. class_avg += student_list[i].scores
  46. print("The average score of the class is {:.2f}".format(class_avg/len(student_list)))
  47.  
  48. return user_input
  49.  
  50. ans = create_sheet()
  51. while ans != "N":
  52. ans = create_sheet()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement