Ilayda-j commited on
Commit
27874a2
1 Parent(s): 24c1fa1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -15
app.py CHANGED
@@ -6,15 +6,14 @@ questions = [
6
  {"question": "What is the underlying message of the poem?", "options": ["The importance of making choices", "The beauty of nature", "The joy of youth", "The value of time"], "correct_option": 0}
7
  ]
8
 
9
- def get_first_question():
10
- current_question = questions[0]
11
- options = "\n".join([f"{idx}. {option}" for idx, option in enumerate(current_question['options'])])
12
- return f"Question 1: {current_question['question']}\n{options}", 0
13
-
14
  def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
15
  output_messages = []
16
-
 
17
  current_question = questions[question_index]
 
 
 
18
 
19
  if user_response is not None:
20
  user_response = int(user_response)
@@ -23,15 +22,11 @@ def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
23
  else:
24
  output_messages.append(f"Incorrect. The correct answer was: {current_question['options'][current_question['correct_option']]}")
25
 
26
- if continue_quiz.lower() == 'no':
27
- output_messages.append("Thank you for participating in the quiz!")
28
- question_index = 0
29
- else:
30
- question_index = (question_index + 1) % len(questions)
31
- next_question = questions[question_index]
32
- output_messages.append(f"\nQuestion {question_index + 1}: {next_question['question']}")
33
- for i, option in enumerate(next_question['options']):
34
- output_messages.append(f"{i}. {option}")
35
 
36
  return "\n".join(output_messages), question_index
37
 
 
6
  {"question": "What is the underlying message of the poem?", "options": ["The importance of making choices", "The beauty of nature", "The joy of youth", "The value of time"], "correct_option": 0}
7
  ]
8
 
 
 
 
 
 
9
  def interactive_quiz(user_response=None, continue_quiz='yes', question_index=0):
10
  output_messages = []
11
+
12
+ # Get the current question
13
  current_question = questions[question_index]
14
+ output_messages.append(f"Question {question_index + 1}: {current_question['question']}")
15
+ for i, option in enumerate(current_question['options']):
16
+ output_messages.append(f"{i}. {option}")
17
 
18
  if user_response is not None:
19
  user_response = int(user_response)
 
22
  else:
23
  output_messages.append(f"Incorrect. The correct answer was: {current_question['options'][current_question['correct_option']]}")
24
 
25
+ if continue_quiz.lower() == 'no':
26
+ output_messages.append("Thank you for participating in the quiz!")
27
+ question_index = 0 # Reset the question index for the next session
28
+ else:
29
+ question_index = (question_index + 1) % len(questions) # Move to the next question
 
 
 
 
30
 
31
  return "\n".join(output_messages), question_index
32