OzoneAsai commited on
Commit
6066cfe
1 Parent(s): 5dd29f2

Update outerElectronFl.py

Browse files
Files changed (1) hide show
  1. outerElectronFl.py +24 -1
outerElectronFl.py CHANGED
@@ -142,5 +142,28 @@ def next_question_element():
142
  session["element"] = random.choice(list(element_outer_electrons.keys()))
143
  return redirect(url_for("quiz_element"))
144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  if __name__ == '__main__':
146
- app.run(debug=True, port=7860)
 
142
  session["element"] = random.choice(list(element_outer_electrons.keys()))
143
  return redirect(url_for("quiz_element"))
144
 
145
+ @app.route('/quiz_element2num', methods=['GET', 'POST'])
146
+ def quiz_element2num():
147
+ # セッションに元素がない場合はランダムに選択
148
+ if "element" not in session:
149
+ session["element"] = random.choice(list(element_atomic_numbers.keys()))
150
+
151
+ if request.method == "POST":
152
+ user_input = int(request.form["user_input"])
153
+ correct_answer = element_atomic_numbers[session["element"]]
154
+ if user_input == correct_answer:
155
+ result = "正解です!"
156
+ else:
157
+ result = f"残念!正解は {correct_answer} でした。"
158
+ return render_template("quiz_element2num.html", element=session["element"], result=result)
159
+
160
+ return render_template("quiz_element2num.html", element=session["element"], result=None)
161
+
162
+ @app.route("/next_element2num", methods=["POST"])
163
+ def next_question_element2num():
164
+ # 次の問題をセッションに設定し、リダイレクト
165
+ session["element"] = random.choice(list(element_atomic_numbers.keys()))
166
+ return redirect(url_for("quiz_element2num"))
167
+
168
  if __name__ == '__main__':
169
+ app.run(debug=True, port=7860)