liveBook · Manning

Quiz system

As explained in Coding with AI

A quiz system is an application that presents questions, accepts answers, and manages assessment interactions and results.

A quiz system presents questions, captures selected answers, stores responses, and advances until the quiz reaches completion. A practical Flask version separates the interface, request routes, question retrieval, answer storage, and results display. section 7.1 section 7.1.3

A minimal implementation needs these cooperating pieces:

A small Flask quiz flow

A SQLite database contains 35 questions. The quiz route loads a question by identifier, displays four radio-button answers, accepts a POST submission, stores the response, and redirects to the next identifier. After the final question, it redirects to a results template. Keep the generated design under review: one proposal introduced SQLAlchemy even though a direct SQLite approach was preferred. section 7.1 section 7.1.3

from flask import Flask, render_template, request, redirect, url_for
from quiz_db import get_questions, store_answer
app = Flask(__name__)
@app.route('/')
def index():
    return redirect(url_for('quiz'))
@app.route('/quiz', methods=['GET', 'POST'])
def quiz():
    question_id = request.args.get('question_id', 1)
    question = get_questions(question_id)
    if request.method == 'POST':
        selected_answer = request.form['answer']
        store_answer(question_id, selected_answer)
        if question_id < 35:
            return redirect(url_for('quiz', question_id=question_id + 1))
        else:
            return redirect(url_for('results'))
    return render_template('quiz.html', question=question)
@app.route('/results')
def results():
    return render_template('results.html')
if __name__ == '__main__':
    app.run(debug=True)

Inspect the compact Flask route implementation showing question selection, POST handling, answer storage, progression, and results navigation. section 7.1.3

How Coding with AI covers it

How deep it goes
Explains routes, persistence, templates, validation, and extensions, but stops short of a fully validated production implementation.
Examples
Uses 35 stored questions, four answer options, an FCC phonetic-alphabet question, radio-button forms, and a completion page.
What it assumes
Assumes Flask and a functional backend, while specifying the frontend flow and database interactions needed to complete the application.
What you can do after
Build a testable Flask quiz frontend that retrieves questions, records submissions, progresses through items, and displays completion results.
How it connects
Connects Flask routes, Jinja templates, SQLite, forms, database persistence, answer storage, and results pages.

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.