Guest User

Untitled

a guest
Oct 18th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. class Question:
  2. def __init__(self, questions, types, q_number):
  3. self.questions = questions
  4. self.types = types
  5. self.num = q_number
  6. def __str__(self):
  7. res = "questions: "+ self.questions
  8. res = res + "\ntype: " + self.types
  9. res = res + "\nq_number: " + str(self.num)
  10. return res
  11.  
  12. class Answer:
  13. def __init__(self,name, points, question):
  14. self.name = name
  15. self.points = points
  16. self.question = question
  17.  
  18. def __str__(self):
  19. res = "name: " + " " + self.name
  20. res = res + "\npoints: " + str(self.points)
  21. res = res + "\n" + str(self.question)
  22. return res
  23.  
  24. class Exam:
  25. def __init__(self, answers):
  26. self.answers = answers
  27.  
  28. # self.total_points = self.evaluation()
  29.  
  30. def evaluation(self): #method. outside the class: function
  31. python_total_points = 0
  32. algorithm_total_points = 0
  33. count_type_python = 0
  34. count_type_algorithm = 0
  35. total_points = 0
  36. for answer in self.answers:
  37.  
  38. if answer.question.types == "python":
  39. python_total_points += answer.points
  40. count_type_python += 1
  41.  
  42.  
  43. if answer.question.types == "algorithm":
  44. algorithm_total_points += answer.points
  45. count_type_algorithm += 1
  46.  
  47.  
  48. if python_total_points < (count_type_algorithm*10)/2 or algorithm_total_points < (count_type_algorithm*10)/2:
  49. return total_points
  50. else:
  51. total_points = python_total_points + algorithm_total_points
  52. return total_points
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. # grade = 0
  60. # total_python = a1.points + a2.points
  61. # total_algorithm = a3.points + a4.points
  62. # if total_algorithm < 10 or total_python < 10:
  63. # return grade
  64. # else:
  65. # grade = total_python + total_algorithm
  66. # return grade
  67.  
  68. def __str__(self):
  69. res = self.answer
  70. res = res + "\ntotal_points: " + str(self.total_points)
  71. return res
  72.  
  73.  
  74.  
  75. q1 = Question('firstq', 'python', 1)
  76. q2 = Question('secondq', 'python', 2)
  77. q3 = Question('thirdq', 'algorithm', 3)
  78. q4 = Question('forthq', 'algorithm', 4)
  79.  
  80. a1 = Answer("Lenka",10, q1)
  81. a2 = Answer("Lenka",8, q2)
  82. a3 = Answer("Lenka",8, q3)
  83. a4 = Answer("Lenka",8, q4)
  84.  
  85. answer = [a1,a2,a3,a4]
  86. exam_1 = Exam(answer)
  87. final_score = exam_1.evaluation()
  88. print("final_score: " + str(final_score))
Add Comment
Please, Sign In to add comment