Update outerElectronFl.py
Browse files- outerElectronFl.py +18 -14
outerElectronFl.py
CHANGED
@@ -1,36 +1,40 @@
|
|
1 |
from flask import Flask, render_template, request, redirect, url_for, session
|
2 |
-
import random
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
app.secret_key = 'your_secret_key_here' # セッションの安全な署名に必要なキー
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return country, capitals[country]
|
14 |
|
15 |
@app.route('/', methods=['GET', 'POST'])
|
16 |
def quiz():
|
17 |
-
if '
|
18 |
-
session['
|
19 |
|
20 |
result = None
|
|
|
21 |
if request.method == 'POST':
|
22 |
user_input = request.form['user_input']
|
23 |
-
if user_input == session['
|
24 |
result = '正解です!'
|
25 |
else:
|
26 |
-
result = '不正解です。正解は{}です。'.format(session['
|
27 |
|
28 |
-
return render_template('quiz.html',
|
29 |
|
30 |
@app.route('/next', methods=['POST'])
|
31 |
def next_question():
|
32 |
-
session.pop('
|
33 |
-
session.pop('
|
34 |
return redirect(url_for('quiz'))
|
35 |
|
36 |
if __name__ == '__main__':
|
|
|
1 |
from flask import Flask, render_template, request, redirect, url_for, session
|
2 |
+
import random
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
app.secret_key = 'your_secret_key_here' # セッションの安全な署名に必要なキー
|
6 |
|
7 |
+
questions = {
|
8 |
+
"What is the capital of France?": "Paris",
|
9 |
+
"What is the largest ocean?": "Pacific",
|
10 |
+
"Which planet is known as the Red Planet?": "Mars",
|
11 |
+
"What is the chemical symbol for water?": "H2O",
|
12 |
+
}
|
13 |
|
14 |
+
def get_random_question():
|
15 |
+
question = random.choice(list(questions.keys()))
|
16 |
+
return question, questions[question]
|
|
|
17 |
|
18 |
@app.route('/', methods=['GET', 'POST'])
|
19 |
def quiz():
|
20 |
+
if 'current_question' not in session: # セッションに現在の問題がない場合は新しいものを取得
|
21 |
+
session['current_question'], session['current_answer'] = get_random_question()
|
22 |
|
23 |
result = None
|
24 |
+
|
25 |
if request.method == 'POST':
|
26 |
user_input = request.form['user_input']
|
27 |
+
if user_input == session['current_answer']:
|
28 |
result = '正解です!'
|
29 |
else:
|
30 |
+
result = '不正解です。正解は{}です。'.format(session['current_answer'])
|
31 |
|
32 |
+
return render_template('quiz.html', question=session['current_question'], result=result)
|
33 |
|
34 |
@app.route('/next', methods=['POST'])
|
35 |
def next_question():
|
36 |
+
session.pop('current_question') # 現在の問題をセッションから削除
|
37 |
+
session.pop('current_answer')
|
38 |
return redirect(url_for('quiz'))
|
39 |
|
40 |
if __name__ == '__main__':
|