Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Question:
- def __init__(self, questions, types, q_number):
- self.questions = questions
- self.types = types
- self.num = q_number
- def __str__(self):
- res = "questions: "+ self.questions
- res = res + "\ntype: " + self.types
- res = res + "\nq_number: " + str(self.num)
- return res
- class Answer:
- def __init__(self,name, points, question):
- self.name = name
- self.points = points
- self.question = question
- def __str__(self):
- res = "name: " + " " + self.name
- res = res + "\npoints: " + str(self.points)
- res = res + "\n" + str(self.question)
- return res
- class Exam:
- def __init__(self, answers):
- self.answers = answers
- # self.total_points = self.evaluation()
- def evaluation(self): #method. outside the class: function
- python_total_points = 0
- algorithm_total_points = 0
- count_type_python = 0
- count_type_algorithm = 0
- total_points = 0
- for answer in self.answers:
- if answer.question.types == "python":
- python_total_points += answer.points
- count_type_python += 1
- if answer.question.types == "algorithm":
- algorithm_total_points += answer.points
- count_type_algorithm += 1
- if python_total_points < (count_type_algorithm*10)/2 or algorithm_total_points < (count_type_algorithm*10)/2:
- return total_points
- else:
- total_points = python_total_points + algorithm_total_points
- return total_points
- # grade = 0
- # total_python = a1.points + a2.points
- # total_algorithm = a3.points + a4.points
- # if total_algorithm < 10 or total_python < 10:
- # return grade
- # else:
- # grade = total_python + total_algorithm
- # return grade
- def __str__(self):
- res = self.answer
- res = res + "\ntotal_points: " + str(self.total_points)
- return res
- q1 = Question('firstq', 'python', 1)
- q2 = Question('secondq', 'python', 2)
- q3 = Question('thirdq', 'algorithm', 3)
- q4 = Question('forthq', 'algorithm', 4)
- a1 = Answer("Lenka",10, q1)
- a2 = Answer("Lenka",8, q2)
- a3 = Answer("Lenka",8, q3)
- a4 = Answer("Lenka",8, q4)
- answer = [a1,a2,a3,a4]
- exam_1 = Exam(answer)
- final_score = exam_1.evaluation()
- print("final_score: " + str(final_score))
Add Comment
Please, Sign In to add comment