What it shows
Teachers in small schools and coaching classes often mark quizzes by hand. A small web app lets students log in, answer multiple-choice questions in a browser, see their score and appear on a leaderboard. The project teaches routes, templates, forms and a database in one application.
The science
Flask maps URLs to Python functions called routes. A GET route shows the question form from an HTML template, and a POST route receives the chosen answers, checks them against the database and saves the score. Sessions remember who is logged in. A SQL query with ORDER BY score DESC LIMIT 10 produces the leaderboard.
Materials
Cost: free. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- A laptop with Python 3 and Flask installed with pip
- SQLite through Python
- A text editor such as VS Code
- A browser
- A list of 20 sample questions with four options each
- A second device on the same Wi-Fi to test (optional)
Safety
For this project: Do not store real passwords. Use hashed passwords from werkzeug.security and sample users only. Do not expose the development server to the internet.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
11 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Create a virtual environment, install Flask and make the project folders: app.py, templates and static.
Design three tables in SQLite: users, questions with correct option, and scores with user id, score and time.
Write a script that loads the 20 sample questions from a CSV file into the database.
Write routes for register and login that hash the password and keep the user in a session.
Write the quiz route that selects 10 random questions and shows them in a form with radio buttons.
Write the submit route that compares answers, counts the score and saves the result with a timestamp.
Show a result page with each question, the right answer and the explanation.
Write the leaderboard route to list the top 10 scores with names and dates.
Add a simple style with CSS so the pages look neat on a phone.
Run it on the laptop IP address and test from a phone on the same Wi-Fi with five friends.
Write the report with screenshots, route table, database diagram and testing notes.
What you should see
Students register, take a 10-question quiz, see their score with answers and appear on the leaderboard. The score table in SQLite matches what each student saw.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1What is a route in Flask?
A URL pattern linked to a Python function that returns a page.
2Why hash passwords?
So that a stolen database does not reveal the actual passwords.
3What is the difference between GET and POST?
GET requests a page, while POST sends form data to the server to be processed.
4What is a session?
Data stored for a user across requests, normally through a signed cookie.
Take it further
Add a timer for each question and an admin page for the teacher to upload new questions as CSV.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
Free ebooks for this project
Programming
Build Five Web Pages with HTML and CSS
A project book: a profile page, a school page, a shop page, a form and a photo gallery
