-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexam.py
51 lines (39 loc) · 1014 Bytes
/
exam.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
"""
@ChatGPT
@Mopheshi
"""
def display_question(question):
print(question)
def get_answer():
answer = input("Your answer: ")
return answer
class Exam:
def __init__(self, ques):
self.questions = ques
self.score = 0
def grade_exam(self):
for question in self.questions:
display_question(question["question"])
answer = get_answer()
if answer.lower() == question["answer"].lower():
self.score += 1
total_questions = len(self.questions)
print("\nExam complete!")
print("Your score: {}/{}".format(self.score, total_questions))
# Example usage
questions = [
{
"question": "What is the capital of France?",
"answer": "Paris"
},
{
"question": "What is the square root of 16?",
"answer": "4"
},
{
"question": "Who wrote the play 'Romeo and Juliet'?",
"answer": "Shakespeare"
}
]
exam = Exam(questions)
exam.grade_exam()