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.

Pat's Quiz

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

functions.py
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_answer

The 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.

An unexpected error has occurred. Reload 🗙

Reconnecting to the server …

Connection failed. Trying again in seconds.

Connection failed. Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session. Please retry or reload the page.