0% found this document useful (0 votes)
2 views2 pages

Program 10

The document outlines the development of a mini Flask-based quiz application for an educational website. It includes a Python script that serves quiz questions and calculates scores based on user answers, as well as an HTML template for displaying the quiz. The app allows users to answer multiple-choice questions and receive their final score upon submission.

Uploaded by

manoharrish3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Program 10

The document outlines the development of a mini Flask-based quiz application for an educational website. It includes a Python script that serves quiz questions and calculates scores based on user answers, as well as an HTML template for displaying the quiz. The app allows users to answer multiple-choice questions and receive their final score upon submission.

Uploaded by

manoharrish3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Flask Mini Quiz Application

Problem Statement
Program Question:

An educational website wants to develop an online multiple-choice quiz where students


answer a series of questions and get their final score at the end.
Build a mini Flask-based quiz app that shows questions, accepts answers,
and calculates the total score.

[Link]
from flask import Flask, render_template, request

app = Flask(__name__)

QUIZ_DATA = [
{"id": 1, "q": "What is 5 + 5?", "options": ["8", "10", "12"],
"ans": "10"},
{"id": 2, "q": "Capital of France?", "options": ["Berlin", "Madrid",
"Paris"], "ans": "Paris"}
]

@[Link]('/')
def quiz():
return render_template('[Link]', questions=QUIZ_DATA)

@[Link]('/submit', methods=['POST'])
def submit():
score = 0
for q in QUIZ_DATA:
user_answer = [Link](str(q['id']))
if user_answer == q['ans']:
score += 1
return f"<h1>Final Score: {score}/{len(QUIZ_DATA)}</h1> <a
href='/'>Restart</a>"

if __name__ == '__main__':
[Link](debug=True)
[Link]
<!DOCTYPE html>
<html>
<head>
<title>Quiz App</title>
</head>
<body>

<h2>Simple Quiz</h2>

<form action="/submit" method="post">

{% for q in questions %}

<p><b>{{ q.q }}</b></p>

{% for opt in [Link] %}


<input type="radio" name="{{ [Link] }}" value="{{ opt }}"
required>
{{ opt }}<br>
{% endfor %}

<br>

{% endfor %}

<button type="submit">Finish Quiz</button>

</form>

</body>
</html>

You might also like