import random
class ToplamaCikarma:
def __init__(self, questions):
self.questions = questions
self.question_index = 0
self.score = 0
def getQuestion(self):
return self.questions[self.question_index]
def display_question(self):
random_soru = random.choice(self.questions)
question = random_soru["question"]
choices = random_soru["choices"]
print(question)
for i, secenek in enumerate(choices, 1):
print(f"{i}. {secenek[1]}")
def guess(self, user_answer):
question, options, answer = self.getQuestion()
if user_answer == answer:
self.score += 1
print(f"Cevap doğru!")
else:
print("Maalesef cevap yanlış...")
self.question_index += 1
soruCevapListesi = [
{ "title": "soru 1: toplama",
"question": "2 + 3 = ?",
"choices": [
[1, "5"],
[0, "4"],
[0, "3"],
[0, "2"]
]
},
{ "title": "soru 2: çıkarma",
"question": "38 - 4 = ?",
"choices": [
[1, "34"],
[0, "35"],
[0, "36"],
[0, "37"]
]
},
{"title": "soru 3: toplama",
"question": "15 + 3 = ?",
"choices": [
[0, "16"],
[0, "17"],
[1, "18"],
[0, "9"]
]
}
]
oyun = ToplamaCikarma(soruCevapListesi)
oyun.display_question()