Compare commits

...
2 Commits
Author SHA1 Message Date
Jordan d80bef959f update doesnt work properly for quiz but eveyrthing else works 2026-08-11 12:36:02 +12:00
Jordan f10b5ac323 Delete accounts.db 2026-08-11 10:32:53 +12:00
5 changed files with 134 additions and 2 deletions
+78
View File
@@ -104,6 +104,31 @@ def view_users():
quiz_data = {
"quizzes": {
"linearprogramming": [
{
"question": "1",
"options": ["1", "2", "3", "4"],
"answer": "1"
},
{
"question": "2",
"options": ["1", "2", "3", "4"],
"answer": "2"
},
{
"question": "3",
"options": ["1", "2", "3", "4"],
"answer": "3"
},
]
}
}
@app.route('/')
def home():
return render_template('index.html')
@@ -113,6 +138,18 @@ def home():
def bivariate():
return render_template('bivariate.html')
@app.route('/linearprogramming')
@login_required
def linearprogramming():
return render_template('linearprogramming.html', quizzes=quiz_data["quizzes"])
@app.route('/start_quiz/<quiz_name>')
def start_quiz(quiz_name):
session['quiz_name'] = quiz_name
session['current_question'] = 0
session['score'] = 0
return redirect(url_for('linearprogrammingquiz'))
@app.route('/simultaneousequations')
@login_required
def simultaneousequations():
@@ -185,5 +222,46 @@ def resetpasscode():
@app.route('/newpassword')
def newpassword():
return render_template('newpassword.html')
@app.route('/linearprogrammingquiz', methods=['GET', 'POST'])
def linearprogrammingquiz():
quiz_name = session.get('quiz_name')
current_question = session.get('current_question', 0) # Default to 0 if not set
quiz_questions = quiz_data["quizzes"].get(quiz_name, [])
if request.method == 'POST':
selected_option = request.form.get('option')
correct_answer = quiz_questions[current_question]['answer']
# Check if the selected answer is correct
if selected_option == correct_answer:
session['score'] = session.get('score', 0) + 1 # Increment score if the answer is correct
feedback = "Correct! Well done."
else:
feedback = f"Wrong! The correct answer is {correct_answer}."
# Move to the next question
session['current_question'] = current_question + 1
session['feedback'] = feedback
if session['current_question'] >= len(quiz_questions):
return redirect(url_for('quiz_result'))
return redirect(url_for('linearprogrammingquiz'))
# Handle GET request: get current question data
if current_question < len(quiz_questions):
current_question_data = quiz_questions[current_question]
feedback = session.pop('feedback', '') # Remove feedback from session
return render_template('quiz_question.html', question_data=current_question_data, current_question=current_question + 1, total_questions=len(quiz_questions), feedback=feedback)
else:
return redirect(url_for('quiz_result'))
@app.route('/quiz_result')
def quiz_result():
score = session.get('score', 0) # Default to 0 if score is not found
quiz_name = session.get('quiz_name')
total_questions = len(quiz_data["quizzes"].get(quiz_name, [])) # Handle case where quiz_name might not be found
if __name__ == '__main__':
app.run(debug=True)
+1 -2
View File
@@ -11,8 +11,7 @@
<li><a href="{{ url_for('about') }}">About</a></li>
{% if session.user_id %}
<li><a href="{{ url_for('bivariate') }}">Bivariate Data</a></li>
<li><a href="{{ url_for('simultaneousequations') }}">Simultaneous Equations</a></li>
<li><a href="{{ url_for('triganometry') }}">Triganometry</a></li>
<li><a href="{{ url_for('linearprogramming') }}">Linear Programming</a></li>
<li style="margin-left: auto; color: white; margin-top: 14px; margin-left: 550px;">Hi, {{ session.username }}</li>
<li style="margin-left: 20px;"><a href="{{ url_for('logout') }}">Sign Out</a></li>
{% else %}
+36
View File
@@ -0,0 +1,36 @@
{% extends 'base.html' %}
{% block content %}
<div class="mainpart">
<h1>Information on linearprogramming</h1>
<div class="information">
<h2>information</h2>
</div>
<div class="formulas">
<h2>formulas</h2>
</div>
<div class="quizzes">
<h2>quizzes</h2>
<ul>
{% for quiz in quizzes %}
<li><a href="{{ url_for('start_quiz', quiz_name=quiz) }}">{{ quiz }}</a></li>
{% endfor %}
</ul>
</div>
</div>
<footer class="sources">
<div class="sourcescontent">
<h2>Sources</h2>
<p class="sourcestext">links to sources would go here</p>
<p class="sourcestext">source one will embed link into text</p>
<p class="sourcestext">source two will embed link into text</p>
<p class="sourcestext">source three will embed link into text</p>
<p class="sourcestext">source four will embed link into text</p>
<div>
</footer>
{% endblock %}
+19
View File
@@ -0,0 +1,19 @@
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
<header>
<h1>Quiz Question</h1>
</header>
<div class="container">
<h2>Question {{ current_question }} of {{ total_questions }}</h2>
<form method="post">
<p>{{ question_data['question'] }}</p>
{% for option in question_data['options'] %}
<div>
<input type="radio" id="{{ option }}" name="option" value="{{ option }}">
<label for="{{ option }}">{{ option }}</label>
</div>
{% endfor %}
<button type="submit">Submit</button>
</form>
<p>{{ feedback }}</p>
View File