Mr-67 commited on
Commit
77c9281
·
verified ·
1 Parent(s): 2c2de63

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -147
main.py DELETED
@@ -1,147 +0,0 @@
1
- from flask import Flask, render_template, request, redirect, url_for, session
2
- import random
3
- import os
4
- import time
5
- app = Flask(__name__)
6
- app.secret_key = "your_secret_key"
7
-
8
-
9
- def generate_question(low, high, operation):
10
- if operation == "Add":
11
- num1 = random.randint(low, high)
12
- num2 = random.randint(low, high)
13
- correct_answer = num1 + num2
14
- question = f"{num1} + {num2}"
15
- symbol = "+"
16
- elif operation == "Subtract":
17
- num1 = random.randint(low, high)
18
- num2 = random.randint(low, high)
19
- if num1 < num2:
20
- num1, num2 = num2, num1
21
- correct_answer = num1 - num2
22
- question = f"{num1} - {num2}"
23
- symbol = "-"
24
- elif operation == "Divide":
25
- num2 = random.randint(max(1, low), high)
26
- answer = random.randint(low, high)
27
- num1 = num2 * answer
28
- correct_answer = answer
29
- question = f"{num1} ÷ {num2}"
30
- symbol = "÷"
31
- else: # Multiply
32
- num1 = random.randint(low, high)
33
- num2 = random.randint(low, high)
34
- correct_answer = num1 * num2
35
- question = f"{num1} × {num2}"
36
- symbol = "×"
37
- return num1, num2, correct_answer, question, symbol
38
-
39
-
40
- @app.route("/", methods=["GET", "POST"])
41
- def configure_quiz():
42
- if request.method == "POST":
43
- session.clear()
44
-
45
- session["low"] = int(request.form["low"])
46
- session["high"] = int(request.form["high"])
47
- session["num_questions"] = int(request.form["num_questions"])
48
- session["operation"] = request.form.get("operation", "Multiply")
49
-
50
- session["questions"] = []
51
- session["correct_answers"] = 0
52
- session["total_attempts"] = 0
53
- session["start_time"] = time.time()
54
-
55
- difficulty = request.form.get("difficulty", "Medium")
56
- time_limits = {"Easy": 30, "Medium": 20, "Hard": 10}
57
- session["difficulty"] = difficulty
58
- session["time_per_question"] = time_limits.get(difficulty, 20)
59
-
60
- return redirect(url_for("quiz"))
61
-
62
- return render_template("configure_quiz.html")
63
-
64
-
65
- @app.route("/quiz", methods=["GET", "POST"])
66
- def quiz():
67
- if "low" not in session or "high" not in session or "num_questions" not in session:
68
- return redirect(url_for("configure_quiz"))
69
-
70
- low = session["low"]
71
- high = session["high"]
72
- num_questions = session["num_questions"]
73
- operation = session.get("operation", "Multiply")
74
-
75
- if "questions" not in session:
76
- session["questions"] = []
77
-
78
- if session["total_attempts"] >= num_questions:
79
- return redirect(url_for("summary"))
80
-
81
- if request.method == "POST":
82
- user_answer = request.form.get("answer")
83
- correct_answer = session["correct_answer"]
84
-
85
- session["total_attempts"] += 1
86
- is_correct = user_answer.isdigit() and int(user_answer) == correct_answer
87
-
88
- if user_answer == "TIMEOUT":
89
- is_correct = False
90
- user_answer = None
91
-
92
- session["questions"].append({
93
- "num1": session["num1"],
94
- "num2": session["num2"],
95
- "question": session["question"],
96
- "correct_answer": correct_answer,
97
- "user_answer": int(user_answer) if user_answer is not None and user_answer.isdigit() else None,
98
- "is_correct": is_correct
99
- })
100
-
101
- if is_correct:
102
- session["correct_answers"] += 1
103
-
104
- if session["total_attempts"] >= num_questions:
105
- return redirect(url_for("summary"))
106
-
107
- num1, num2, correct_answer, question, symbol = generate_question(low, high, operation)
108
-
109
- session["num1"] = num1
110
- session["num2"] = num2
111
- session["question"] = question
112
- session["correct_answer"] = correct_answer
113
- session["symbol"] = symbol
114
-
115
- return render_template(
116
- "quiz.html",
117
- num1=num1,
118
- num2=num2,
119
- symbol=symbol,
120
- correct_answer=correct_answer,
121
- correct=session.get("correct_answers", 0),
122
- total=session.get("total_attempts", 0),
123
- num_questions=num_questions
124
- )
125
-
126
-
127
- @app.route("/summary")
128
- def summary():
129
- end_time = time.time()
130
- session["total_time"] = round(end_time - session.get("start_time", end_time))
131
-
132
- return render_template(
133
- "summary.html",
134
- low=session["low"],
135
- high=session["high"],
136
- num_questions=session["num_questions"],
137
- questions=session.get("questions", []),
138
- correct=session.get("correct_answers", 0),
139
- total=session.get("total_attempts", 0),
140
- total_time=session["total_time"],
141
- operation=session.get("operation", "Multiply"),
142
- difficulty=session.get("difficulty", "Medium")
143
- )
144
-
145
-
146
- if __name__ == "__main__":
147
- app.run(debug=True, host="0.0.0.0", port=5000)