Spaces:
Runtime error
Runtime error
Update routes/chatbot_routes.py
Browse files- routes/chatbot_routes.py +10 -7
routes/chatbot_routes.py
CHANGED
|
@@ -131,6 +131,7 @@ def submit_answer():
|
|
| 131 |
user_id = request.json.get("user_id", "default")
|
| 132 |
answer = request.json.get("answer", "").strip()
|
| 133 |
state = quiz_state.get(user_id, {})
|
|
|
|
| 134 |
|
| 135 |
if not state:
|
| 136 |
return jsonify({"reply": "No active quiz found. Start a quiz first."})
|
|
@@ -143,14 +144,16 @@ def submit_answer():
|
|
| 143 |
|
| 144 |
correct_answer = questions[current_index]["answer"].strip()
|
| 145 |
|
| 146 |
-
# Adjust the score based on the user's answer
|
| 147 |
-
if
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
else:
|
| 151 |
-
|
| 152 |
-
feedback = f"Incorrect! The correct answer was: {correct_answer}. -5 points. Your current score: {state['score']}."
|
| 153 |
-
|
| 154 |
# Move to the next question
|
| 155 |
state["current"] += 1
|
| 156 |
|
|
|
|
| 131 |
user_id = request.json.get("user_id", "default")
|
| 132 |
answer = request.json.get("answer", "").strip()
|
| 133 |
state = quiz_state.get(user_id, {})
|
| 134 |
+
time_up = request.json.get("timeUp", False)
|
| 135 |
|
| 136 |
if not state:
|
| 137 |
return jsonify({"reply": "No active quiz found. Start a quiz first."})
|
|
|
|
| 144 |
|
| 145 |
correct_answer = questions[current_index]["answer"].strip()
|
| 146 |
|
| 147 |
+
# Adjust the score based on the user's answer and timeUp flag
|
| 148 |
+
if not time_up:
|
| 149 |
+
if answer.lower() == correct_answer.lower():
|
| 150 |
+
state["score"] += 10 # Add 10 points for a correct answer
|
| 151 |
+
feedback = f"Correct! +10 points. Your current score: {state['score']}."
|
| 152 |
+
else:
|
| 153 |
+
state["score"] -= 5 # Deduct 5 points for an incorrect answer
|
| 154 |
+
feedback = f"Incorrect! The correct answer was: {correct_answer}. -5 points. Your current score: {state['score']}."
|
| 155 |
else:
|
| 156 |
+
feedback = f"Time's up! The correct answer was: {correct_answer}. No points awarded."
|
|
|
|
|
|
|
| 157 |
# Move to the next question
|
| 158 |
state["current"] += 1
|
| 159 |
|