WAQASCHANNA commited on
Commit
c675bc7
·
verified ·
1 Parent(s): 541d869

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -32,21 +32,27 @@ def game_mode(topic):
32
  question, choices = generate_question(topic)
33
 
34
  st.write(question)
35
- answer = st.radio("Select your answer:", choices)
36
 
37
- # Start the timer
38
- time_elapsed = time.time() - start_time
39
- time_left = 30 - int(time_elapsed) # Set timer to 30 seconds per question
40
-
41
- st.write(f"Time left: {time_left} seconds")
42
 
43
- if st.button("Submit"):
44
- st.write("You selected:", answer)
45
- st.write(f"Time taken: {int(time_elapsed)} seconds")
46
- if time_elapsed >= 30:
47
- st.warning("Time's up!")
48
- else:
49
- st.success("Good job!")
 
 
 
 
 
 
 
 
 
50
 
51
  def quiz_mode(topic):
52
  st.write("Quiz Mode: Take your time!")
@@ -54,11 +60,21 @@ def quiz_mode(topic):
54
  question, choices = generate_question(topic)
55
 
56
  st.write(question)
57
- answer = st.radio("Select your answer:", choices)
58
 
59
- if st.button("Submit"):
60
- st.write("You selected:", answer)
61
- st.success("Great! On to the next question!")
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  def main():
64
  st.title("Grok-Powered Quiz App")
 
32
  question, choices = generate_question(topic)
33
 
34
  st.write(question)
 
35
 
36
+ # Use session state to track whether the answer has been submitted
37
+ if 'submitted' not in st.session_state:
38
+ st.session_state.submitted = False
 
 
39
 
40
+ if not st.session_state.submitted:
41
+ answer = st.radio("Select your answer:", choices)
42
+ submit_button = st.button("Submit")
43
+
44
+ if submit_button:
45
+ st.session_state.submitted = True
46
+ st.write("You selected:", answer)
47
+ time_elapsed = time.time() - start_time
48
+ st.write(f"Time taken: {int(time_elapsed)} seconds")
49
+ if time_elapsed >= 30:
50
+ st.warning("Time's up!")
51
+ else:
52
+ st.success("Good job!")
53
+
54
+ else:
55
+ st.write("You've already submitted your answer.")
56
 
57
  def quiz_mode(topic):
58
  st.write("Quiz Mode: Take your time!")
 
60
  question, choices = generate_question(topic)
61
 
62
  st.write(question)
 
63
 
64
+ # Use session state to track whether the answer has been submitted
65
+ if 'submitted' not in st.session_state:
66
+ st.session_state.submitted = False
67
+
68
+ if not st.session_state.submitted:
69
+ answer = st.radio("Select your answer:", choices)
70
+ submit_button = st.button("Submit")
71
+
72
+ if submit_button:
73
+ st.session_state.submitted = True
74
+ st.write("You selected:", answer)
75
+ st.success("Great! On to the next question!")
76
+ else:
77
+ st.write("You've already submitted your answer.")
78
 
79
  def main():
80
  st.title("Grok-Powered Quiz App")