-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_Demo.py
More file actions
71 lines (51 loc) · 2.01 KB
/
OOP_Demo.py
File metadata and controls
71 lines (51 loc) · 2.01 KB
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
60
61
62
63
64
65
66
67
68
class Question:
def __init__(self, text, choices, answer):
self.text = text
self.choices = choices
self.answer = answer
def checkAnswer(self, answer):
return self.answer == answer
class Quiz:
def __init__(self, questions):
self.questions = questions
self.score = 0
self.questionIndex = 0
def getQuestion(self):
return self.questions[self.questionIndex]
def displayQuestion(self):
question = self.getQuestion()
print(f'Soru {self.questionIndex + 1}: {question.text}')
for i in question.choices:
print('-'+i)
answer = input('cevap : ')
self.guess(answer)
self.loadQuestion()
def guess(self, answer):
question = self.getQuestion()
if question.checkAnswer(answer):
self.score += 1
self.questionIndex += 1
def loadQuestion(self):
if len(self.questions) == self.questionIndex:
self.showScore()
self.displayProgress()
else:
self.displayProgress()
self.displayQuestion()
def showScore(self):
print('Score: ', self.score)
def displayProgress(self):
totalQuestion = len(self.questions)
questionNumber = self.questionIndex + 1
if questionNumber > totalQuestion:
print('Quiz End')
else:
print(f'Question {questionNumber} of {totalQuestion}'.center(100, 'x'))
q1 = Question('En iyi proglama dili hangisidir?', ['C#', 'Python', 'Java', 'CSS'], 'Python')
q2 = Question('En popüler proglama dili hangisidir?', ['Python', 'C#', 'Java', 'CSS'], 'Python')
q3 = Question('En çok kazandıran proglama dili hangisidir?', ['CSS', 'C#', 'Python', 'Java'], 'Python')
q4 = Question('En çok sevilen proglama dili hangisidir?', ['CSS', 'C#', 'Python', 'Java'], 'Python')
q5 = Question('En kolay proglama dili hangisidir?', ['CSS', 'C#', 'Python', 'Java'], 'Python')
questions = [q1, q2, q3, q4, q5]
quiz = Quiz(questions)
quiz.loadQuestion()