Repository navigation
Expand file tree
/
Copy pathquiz.py
More file actions
55 lines (44 loc) · 1.51 KB
/
Copy pathquiz.py
File metadata and controls
55 lines (44 loc) · 1.51 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
#Ouestion sınıfı
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
#Quiz sınıfı
class Quiz:
def __init__(self,questions):
self.questions=questions
self.score=0
self.questionIndex=0
def getQuestion(self):
return self.questions[quiz.questionIndex]
def displayQuestion(self):
question=self.getQuestion()
print(f"Soru {self.questionIndex+1}: {question.text}")
for q in question.choices:
print("-"+q)
answer=input("cevap:")
self.guess(answer)
self.loadQuestion()
def quess(self,answer):
question=self.getQuestion
if question.checkAnswer(answer):
self.score+=1
self.questionIndex+=1
self.displayQuestion()
def loadQuestion(self):
if len(self.questions)==self.questionIndex:
self.showScore()
else:
self.displayQuestion()
def showScoer(self):
print(f"Score:{self.score}")
q1=Question("En iyi programalam dili hangisidir ?",["c#","python","javascript","java"],"python")
q2=Question("En popüler programalam dili hangisidir ?",["c#","python","javascript","java"],"c#")
q3=Question("En kazandıran programalam dili hangisidir ?",["c#","python","javascript","java"],"python")
questions=[q1,q2,q3]
quiz=Quiz(questions)
quiz.displayQuestion()
question=quiz.getQuestion()