From d80bef959f5d251a5b685dcd75e494ead08c8d54 Mon Sep 17 00:00:00 2001 From: Jordan Date: Tue, 11 Aug 2026 12:36:02 +1200 Subject: [PATCH] update doesnt work properly for quiz but eveyrthing else works --- app.py | 78 +++++++++++++++++++++++++++ instance/accounts.db | Bin 0 -> 16384 bytes templates/base.html | 3 +- templates/linearprogramming.html | 36 +++++++++++++ templates/linearprogrammingquiz.html | 19 +++++++ templates/quiz_result.html | 0 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 instance/accounts.db create mode 100644 templates/linearprogramming.html create mode 100644 templates/linearprogrammingquiz.html create mode 100644 templates/quiz_result.html diff --git a/app.py b/app.py index df08a9b..928c4ed 100644 --- a/app.py +++ b/app.py @@ -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/') +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) diff --git a/instance/accounts.db b/instance/accounts.db new file mode 100644 index 0000000000000000000000000000000000000000..2b5e5871f5473962a8fc5d41365cbcbd4e3cc776 GIT binary patch literal 16384 zcmeI#%SyvQ6oBDLThs=6*_3W)BTYcW)=j~Uu>>u~Xk#jL6(Wr^(2F)Lx)s4k@j?0m zzK%;fg^Crc`|=OWggNIVllhX(T(_Kf63M&Kco0tHp(qMX6UR~tA+&kV%=@zaHecq} zT{W@)YUTdaB{smTybnI&o~NBGS;aaaT57-#)cH>0bKMZ9C4M)Uzr*3QvViKRbhHAx}#KcYAC9K zh5!NxAb{@>Kk%f1jm009ILKmY**5I_I{1Q1vVaQ^2< YKmY**5I_I{1Q0*~0R#|0VDkk&0d^8)I{*Lx literal 0 HcmV?d00001 diff --git a/templates/base.html b/templates/base.html index 379ca48..bfb2f3d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -11,8 +11,7 @@
  • About
  • {% if session.user_id %}
  • Bivariate Data
  • -
  • Simultaneous Equations
  • -
  • Triganometry
  • +
  • Linear Programming
  • Hi, {{ session.username }}
  • Sign Out
  • {% else %} diff --git a/templates/linearprogramming.html b/templates/linearprogramming.html new file mode 100644 index 0000000..dbe5036 --- /dev/null +++ b/templates/linearprogramming.html @@ -0,0 +1,36 @@ +{% extends 'base.html' %} +{% block content %} +
    +

    Information on linearprogramming

    + +
    +

    information

    + +
    + +
    +

    formulas

    + +
    + +
    +

    quizzes

    +
      + {% for quiz in quizzes %} +
    • {{ quiz }}
    • + {% endfor %} +
    +
    + +
    +
    +
    +

    Sources

    +

    links to sources would go here

    +

    source one will embed link into text

    +

    source two will embed link into text

    +

    source three will embed link into text

    +

    source four will embed link into text

    +
    +
    +{% endblock %} \ No newline at end of file diff --git a/templates/linearprogrammingquiz.html b/templates/linearprogrammingquiz.html new file mode 100644 index 0000000..a997294 --- /dev/null +++ b/templates/linearprogrammingquiz.html @@ -0,0 +1,19 @@ + + + +
    +

    Quiz Question

    +
    +
    +

    Question {{ current_question }} of {{ total_questions }}

    +
    +

    {{ question_data['question'] }}

    + {% for option in question_data['options'] %} +
    + + +
    + {% endfor %} + +
    +

    {{ feedback }}

    \ No newline at end of file diff --git a/templates/quiz_result.html b/templates/quiz_result.html new file mode 100644 index 0000000..e69de29