Own project · Stop 3 of 10
Pat's Quiz
A quiz program with a window: general knowledge, Python, English, vocabulary and abbreviations, with a high score.

Goal
Turn the Python basics into a real program with a user interface.
Implementation
- Interface with tkinter and a custom color scheme (ttk theme).
- Questions and results are kept in an SQLite database and in CSV files.
- Classes for the windows, the random choice of questions and the high score list.
Code
Drawing a question with two wrong answers
def random_generate(library):
if library == 1:
dictionary = open_base()
elif library == 2:
dictionary = open_python()
elif library == 3:
dictionary = open_english()
data_count = len(dictionary)
data_count -= 1
rnd = randint(0, data_count)
rnd_w1 = randint(0, data_count)
rnd_w2 = randint(0, data_count)
for i in dictionary[f"id{rnd}"]:
term = (i['term'])
definition = (i['definition'])
if library == 2:
beginner_explanation = (i['beginner_explanation'])
else:
beginner_explanation = None
wrong1 = dictionary[f"id{rnd_w1}"][-1]['definition']
wrong2 = dictionary[f"id{rnd_w2}"][-1]['definition']
answers = [definition, wrong1, wrong2]
shuffle(answers)
right_answer = definition
return term, definition, answers, beginner_explanation, right_answerThe right answer is shuffled together with two random wrong ones.
What I learned
Splitting a program into classes and files. The interface took more work than the logic behind it.