update doesnt work properly for quiz but eveyrthing else works
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user