-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
59 lines (50 loc) · 1.99 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Question:
def __init__(self, questionId, markedOption, score, status="Not Answered"):
self.questionId = questionId
self.markedOption = markedOption
self.score = score
self.status = status
class Student:
def __init__(self, registedId, questionsAttempted):
self.registedId = registedId
self.questionsAttempted = questionsAttempted
def evaluateQuestions(self, answerKey, questionsAttemptedlist):
for key, value in answerKey:
for i in range(len(questionsAttemptedlist)):
if questionsAttemptedlist[i].questionId == key:
if questionsAttemptedlist[i].markedOption == value:
questionsAttemptedlist[i].status = "correct"
else:
questionsAttemptedlist[i].status = "incorrect"
def findGrade(self, questionsAttemptedlist):
totalScore = 0
for i in range(len(questionsAttemptedlist)):
if questionsAttemptedlist[i].status == "correct":
totalScore += questionsAttemptedlist[i].score
if totalScore >= 80:
return "A"
elif totalScore >= 70 and totalScore < 80:
return "B"
elif totalScore >= 60 and totalScore < 70:
return "C"
else:
return "F"
noOfQuestions = int(input())
questionsAttemptedlist = []
for i in range(noOfQuestions):
questionId = input()
markedOption = input()
score = int(input())
questionsAttemptedlist.append(
Question(questionId, markedOption, markedOption))
countAnswerKey = int(input())
answerKey = {}
for i in range(countAnswerKey):
questionId = input()
answer = input()
answerKey[questionId] = answer
studentObj = Student.evaluateQuestions(answerKey, questionsAttemptedlist)
for i in range(len(questionsAttemptedlist)):
print(questionsAttemptedlist[i].questionId +
" " + questionsAttemptedlist[i].status)
print(studentObj.findGrade(questionsAttemptedlist))