OzoneAsai commited on
Commit
c635f8e
·
verified ·
1 Parent(s): 9d8191e

Update outerElectronFl.py

Browse files
Files changed (1) hide show
  1. outerElectronFl.py +35 -1
outerElectronFl.py CHANGED
@@ -264,4 +264,38 @@ capitals = {
264
  "Pb(NO3)2": "硝酸鉛(II)",
265
  "Pb(CH3COO)2": "酢酸鉛(II)",
266
  "Pb(MnO4)2": "過マンガン酸鉛(II)",
267
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  "Pb(NO3)2": "硝酸鉛(II)",
265
  "Pb(CH3COO)2": "酢酸鉛(II)",
266
  "Pb(MnO4)2": "過マンガン酸鉛(II)",
267
+ }
268
+ # -*- coding: utf-8 -*-
269
+ from flask import Flask, render_template, request, redirect, url_for, session
270
+ import random
271
+
272
+ app = Flask(__name__)
273
+ app.secret_key = 'your_secret_key_here' # セッションの安全な署名に必要なキー
274
+
275
+ def get_random_country():
276
+ country = random.choice(list(capitals.keys()))
277
+ return country, capitals[country]
278
+
279
+ @app.route('/', methods=['GET', 'POST'])
280
+ def quiz():
281
+ if 'current_化合物' not in session: # セッションに現在の化合物がない場合は新しいものを取得
282
+ session['current_化合物'], session['current_化合物名'] = get_random_country()
283
+
284
+ result = None
285
+ if request.method == 'POST':
286
+ user_input = request.form['user_input']
287
+ if user_input == session['current_化合物']:
288
+ result = '正解です!'
289
+ else:
290
+ result = '不正解です。正解は{}です。'.format(session['current_化合物'])
291
+
292
+ return render_template('quiz.html', element=session['current_化合物名'], result=result)
293
+
294
+ @app.route('/next', methods=['POST'])
295
+ def next_question():
296
+ session.pop('current_化合物') # 現在の化合物をセッションから削除
297
+ session.pop('current_化合物名')
298
+ return redirect(url_for('quiz'))
299
+
300
+ if __name__ == '__main__':
301
+ app.run(debug=True, port=7860, host="0.0.0.0")